【发布时间】:2016-10-21 19:26:50
【问题描述】:
首先我会说我是 C# MVC 新手,但我已经建立了一个带有身份管理的站点,并使用一些自定义表扩展了数据库以存储有关我的用户的其他信息,所以我不是总新手。我一直在开发一个我想从我的新网站部署的 VB WPF 应用程序,这就是我遇到问题的地方。
我创建了一个新控制器(用户)和几个视图(下载)和(设置)。我创建了下载视图使用的下载模型。
抽象地说,我正在做的是显示下载视图 (get),其中包含三个复选框以确认用户已阅读概述、安装和服务条款。这些是模型中的布尔值。我在模型中还有一条字符串响应消息,显示在提交按钮的正上方。这是模型:
public class DownloadModel
{
public bool Overview { get; set; }
public bool Installation { get; set; }
public bool TermsOfService { get; set; }
public string Response { get; set; }
public DownloadModel()
{
Overview = false;
Installation = false;
TermsOfService = false;
Response = "After checking boxes click the button to begin installation";
}
}
我的用户控制器处理 Get 以最初显示下载视图,然后在 Post 中检查是否选中了所有复选框,如果没有,它会更新响应消息并返回视图。 如果所有复选框都被选中,那么它会拉出订阅者(它必须存在,因为它是在用户通过帐户控制器 - 身份管理验证他们的电子邮件时创建的),然后继续使用原始订阅者(如果是新的)更新订阅者或上次下载日期。此时我要开始下载 clickonce setup.exe 文件,然后返回设置视图。
[Authorize]
public class UserController : Controller
{
// GET: User/Download
public ActionResult Download()
{
return View(new DownloadModel { });
}
// Post: User/Download
[HttpPost]
public ActionResult Download(DownloadModel downloadcheck)
{
if (!ModelState.IsValid)
{
return View(downloadcheck);
}
//check to see if all the boxes were checked
if (downloadcheck.Overview == true &
downloadcheck.Installation == true &
downloadcheck.TermsOfService == true)
{
//yes - so let's proceed
//first step is to get the subscriber
Subscriber tSubscriber = new Subscriber();
tSubscriber.Email = User.Identity.Name;
bool okLoad = tSubscriber.LoadByEmail();
if (okLoad == false)
{
//we have a real problem. a user has logged in but they are not yet
//a valid subscriber?
throw new Exception("Subscriber not found");
}
// update subscriber with download in process...
if (tSubscriber.OriginalDownload == DateTime.MinValue)
{
tSubscriber.OriginalDownload = DateTime.Now;
tSubscriber.LastDownload = tSubscriber.OriginalDownload;
}
else
{
tSubscriber.LastDownload = DateTime.Now;
}
if (tSubscriber.UpdateDownloaded() == false)
{
//update of download dates failed
//another problem that shouldnt occur.
downloadcheck.Response = "A problem occured downloading your setup."
+ "Try again. If this error continues please contact support.";
return View(downloadcheck);
}
//download dates have been updated for the subscriber so let's start the download!
//THIS IS WHERE I NEED TO BEGIN THE DOWNLOAD
return View("Setup");
}
else
{
// all boxes were not checked - update message
downloadcheck.Response = "Please confirm you have reviewed the above information "
+ "by checking all of the boxes before clicking on the button.";
return View(downloadcheck);
}
}
}
下载视图非常简单,设置视图只是确认下载已开始并提供指向帮助设置页面的链接。
我真的有点迷路了。我以为我会插入一个返回新文件路径响应,但我不能这样做并返回设置视图。
我的另一个想法是在返回时从设置视图中以某种方式触发我的 /xxx/setup.exe 的下载 - 但我不知道如何完成此操作。
我会第一个承认我的 mvc c# 代码可能过于冗长,而且我的做法可能是完全错误的,但我只是在争先恐后地完成这件事,以便我可以部署我的用于选择 Beta 用户进行测试的 WPF 应用程序。靠积蓄谋生已经很长时间了,我可以从这里闻到生活气息。
最后一点,为了简单起见,我使用 setup.exe clickonce 部署我的 wpf 应用程序,因为有 .net 和 localsqldb 先决条件,但我不会使用自动更新 - 这并不是真的相关。
感谢所有意见和建议。
【问题讨论】:
标签: asp.net-mvc clickonce