Guest User

Untitled

a guest
Feb 10th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1.   if (ModelState.IsValid)
  2.             {
  3.  
  4.  
  5.                 if (file != null && file.ContentLength > 0)
  6.                 {
  7.                     var fileName = Path.GetFileName(file.FileName);
  8.                     MainFileDetails mainFileDetail = new MainFileDetails()
  9.                     {
  10.                         FileName = fileName,
  11.                         Extension = Path.GetExtension(fileName),
  12.                         Id = Guid.NewGuid(),
  13.                         FurnitureId = furniture.FurnitureId
  14.                     };
  15.                     var pathMain = Path.Combine(Server.MapPath("~/Upload/MainPage/"), mainFileDetail.Id + mainFileDetail.Extension);
  16.                     file.SaveAs(pathMain);
  17.                     db.Entry(mainFileDetail).State = EntityState.Modified;
  18.                 }
  19.                 foreach (HttpPostedFileBase image in fileTwo)
  20.                 {
  21.  
  22.                     FileDetail fileDetail = new FileDetail()
  23.                     {
  24.  
  25.                         NameFile = image.FileName,
  26.                         Extension = Path.GetExtension(image.FileName), //or mainFileDetail.Extension
  27.                         Id = Guid.NewGuid(),
  28.                         FurnitureId = furniture.FurnitureId //or mainFileDetail. FurnitureId
  29.                     };
  30.                     var path = Path.Combine(Server.MapPath("~/Upload/"), fileDetail.Id + fileDetail.Extension);
  31.                     image.SaveAs(path);
  32.                     // create an instance of FileDetails and set its details based on
  33.                     // the values of image and save
  34.                 }
  35.                 db.Entry(furniture).State = EntityState.Modified;
  36.                 db.SaveChanges();
  37.  
  38.             }
  39.            
  40.  
  41.  
  42.             ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", furniture.CategoryId);
  43.             return View(furniture);
  44.            
  45.         }
Advertisement
Add Comment
Please, Sign In to add comment