public ActionResult Create(CreatePhotoViewModels photo, HttpPostedFileBase photoUpload) { Photo photoToDB = PhotoMapper.MapCreatePhotoViewModel(photo); try { photoToDB.UserID = userID; photoToDB.Id = Guid.NewGuid(); photoToDB.Date = DateTime.Now; photoToDB.Path = $" /Photos/{photoUpload.FileName}"; photoRepository.AddPhotoToDB(photoToDB); photoUpload.SaveAs(Path.Combine(Server.MapPath("~/Photos"), photoUpload.FileName)); return(Content(photoUpload.FileName)); } catch { var model = PhotoMapper.MapCreatePhotoViewModel(photoToDB); var albums = albumRepository.GettAllAlbumsByUserID(userID); model.Albums.Add(new SelectListItem { Text = "Uncategorized", Value = "" }); albums.ForEach(x => model.Albums.Add(new SelectListItem { Text = x.Name, Value = x.Id.ToString() })); return(Content(photoUpload.FileName)); } }
internal static Photo MapCreatePhotoViewModel(CreatePhotoViewModels photo) { return(new Photo { Name = photo.Name, Description = photo.Description, AlbumID = photo.AlbumId != null ? photo.AlbumId : Guid.Empty }); }
// GET: User/Edit/Create public ActionResult Create() { var model = new CreatePhotoViewModels(); var albums = albumRepository.GettAllAlbumsByUserID(userID); model.Albums.Add(new SelectListItem { Text = "Uncategorized", Value = "" }); albums.ForEach(x => model.Albums.Add(new SelectListItem { Text = x.Name, Value = x.Id.ToString() })); return(View(model)); }