示例#1
0
 public ActionResult Edit(UserProfileModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (model.NewPhoto != null)
             {
                 string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Users/" +
                                                  FilePathGenerator.GenerateFileName(model.NewPhoto.FileName));
                 if (!string.IsNullOrEmpty(model.PhotoPath) && System.IO.File.Exists(model.PhotoPath))
                 {
                     System.IO.File.Delete(model.PhotoPath);
                 }
                 model.NewPhoto.SaveAs(filepath);
                 model.PhotoPath = filepath;
             }
             userService.UpdateUserProfile(model.ToServiceUserProfile());
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(View("Error"));
     }
 }