コード例 #1
0
 public ActionResult Edit(AuthorEditModel model)
 {
     try
     {
         if (model.NewPhoto != null)
         {
             string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" +
                                              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;
         }
         var author = model.ToServiceAuthor();
         service.UpdateAuthor(author);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(View("Error"));
     }
 }
コード例 #2
0
 public ActionResult Create(AuthorCreateModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             int id;
             if (model.Photo != null)
             {
                 string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" +
                                                  FilePathGenerator.GenerateFileName(model.Photo.FileName));
                 model.Photo.SaveAs(filepath);
                 id = service.AddAuthor(model.ToServiceAuthor(filepath));
             }
             else
             {
                 id = service.AddAuthor(model.ToServiceAuthor());
             }
             return(RedirectToAction("Details", new { id = id }));
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(View("Error"));
     }
 }
コード例 #3
0
ファイル: File.cs プロジェクト: ArtemProkopovich/Project
        public static string SaveFile(HttpServerUtilityBase server, HttpPostedFileBase file, string directory)
        {
            string filepath = server.MapPath(directory + FilePathGenerator.GenerateFileName(file.FileName));

            file.SaveAs(filepath);
            return(filepath);
        }