我是Webmatrix的新手,并尝试使用可以更新的照片创建个人资料页面。我似乎无法弄清楚为什么它不起作用,但我的代码看起来很好。有人可以看看下面的代码,让我们知道我做错了什么?
免责声明 - 我是一名黑客开发人员,试图自学,所以请原谅我所看到的错误语法和其他任何内容。
@{
if (!WebSecurity.IsAuthenticated) {
Response.Redirect("~/Account/Login?returnUrl="
+ Request.Url.LocalPath);
}
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Update Profile";
WebImage photo = null;
var newFileName = "";
var imagePath = "";
var UserID = "";
var Email = "";
var FirstName = "";
var LastName = "";
var DOB = "";
var EmploymentStatus = "";
var CurrentTitle = "";
var Company = "";
var LinkedInURL = "";
var Resume = "";
var Photo = "";
var ContractorIntro = "";
if(!IsPost){
if(!Request.QueryString["UserID"].IsEmpty() && Request.QueryString["UserID"].IsInt()) {
UserID = Request.QueryString["UserID"];
var db = Database.Open("JobsLoop");
var dbCommand = "SELECT * FROM UserProfile WHERE UserID = @0";
var row = db.QuerySingle(dbCommand, UserID, DOB);
if(row != null) {
UserID = row.UserID.ToString();
FirstName = row.FirstName;
LastName = row.LastName;
EmploymentStatus = row.EmploymentStatus;
CurrentTitle = row.CurrentTitle;
Company = row.Company;
DOB = row.DOB.ToString(format: "dd/MM/yy");
LinkedInURL = row.LinkedInURL;
Resume = row.Resume;
Photo = row.Photo;
ContractorIntro = row.ContractorIntro;
}
}
else{
Validation.AddFormError("No Profile was selected.");
// Use the following line instead for versions of ASP.NET Web Pages 2 earlier
// than the RC release.
//ModelState.AddFormError("No movie was selected.");
}
}
if(IsPost){
Validation.RequireField("UserID", "You must enter a user ID");
Validation.RequireField("FirstName", "First Name is required");
Validation.RequireField("LastName", "No Last Name was submitted!");
Validation.RequireField("DOB", "No DOB was submitted!");
Validation.RequireField("EmploymentStatus", "No Employment Status was submitted!");
Validation.RequireField("CurrentTitle", "No Current Title was submitted!");
//Validation.RequireField("LinkedInURL", "No LinkedIn address was submitted!");
UserID = Request.Form["UserID"];
FirstName = Request.Form["FirstName"];
LastName = Request.Form["LastName"];
DOB = Request.Form["DOB"];
EmploymentStatus = Request.Form["EmploymentStatus"];
CurrentTitle = Request.Form["CurrentTitle"];
Company = Request.Form["Company"];
LinkedInURL = Request.Form["LinkedInURL"];
Resume = Request.Form["Resume"];
Photo = Request.Form["Photo"];
ContractorIntro = Request.Unvalidated["ContractorIntro"];
if(Validation.IsValid()){
photo = WebImage.GetImageFromRequest();
if(photo != null)
{
newFileName = Guid.NewGuid().ToString() + "_" +
Path.GetFileName(photo.FileName);
imagePath = @"profile\" + newFileName;
photo.Save(@"~\" + imagePath);
Photo = @newFileName;
}
else
{
}
if(newFileName.IsEmpty())
{
var db = Database.Open("JobsLoop");
var updateCommand = "UPDATE UserProfile SET FirstName=@1, LastName=@2, DOB=@3, EmploymentStatus=@4, CurrentTitle=@5, Company=@6, LinkedInURL=@7, Resume=@8, ContractorIntro=@9 WHERE UserID=@0";
db.Execute(updateCommand, UserID, FirstName, LastName, DOB, EmploymentStatus, CurrentTitle, Company, LinkedInURL, Resume, ContractorIntro);
}
else{
if(Validation.IsValid()){
var db = Database.Open("JobsLoop");
var updateCommand = "UPDATE UserProfile SET FirstName=@1, LastName=@2, DOB=@3, EmploymentStatus=@4, CurrentTitle=@5, Company=@6, LinkedInURL=@7, Resume=@8, ContractorIntro=@9, Photo=@10 WHERE UserID=@0";
db.Execute(updateCommand, UserID, FirstName, LastName, DOB, EmploymentStatus, CurrentTitle, Company, LinkedInURL, Resume, ContractorIntro, Photo);
}
}
}
}
}