public ActionResult Create(DetailPhotoViewModel pic, HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage != null && uploadImage.ContentLength <= 2000000 && uploadImage.ContentType.Contains("image")) { string fileName = System.IO.Path.GetFileName(uploadImage.FileName); uploadImage.SaveAs(Server.MapPath("~/Files/" + fileName)); PhotoDTO photo = new PhotoDTO { Description = pic.Description, Name = fileName, UploadTime = DateTime.Now, Path = "/Files/" + fileName, AuthorId = User.Identity.GetUserId() }; photoService.Add(photo); return(RedirectToAction("Index")); } return(View("Error")); }
public ActionResult Detail(int?id) { PhotoDTO photoDto; try { photoDto = photoService.GetById(id); } catch (ValidationException ex) { return(Content(ex.Message)); } ViewBag.returnUrl = Request.UrlReferrer; ViewBag.HaveMark = photoService.HaveMark(User.Identity.GetUserId(), photoDto.Id); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhotoDTO, DetailPhotoViewModel>()).CreateMapper(); DetailPhotoViewModel photoView = mapper.Map <PhotoDTO, DetailPhotoViewModel>(photoDto); return(View(photoView)); }
public ActionResult Delete(int?id) { PhotoDTO photoDto; try { photoDto = photoService.GetById(id); } catch (ValidationException ex) { return(Content(ex.Message)); } if (User.Identity.GetUserName() == photoDto.AuthorUsername || User.IsInRole("moderator")) { ViewBag.Id = id; var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhotoDTO, DetailPhotoViewModel>()).CreateMapper(); DetailPhotoViewModel photoView = mapper.Map <PhotoDTO, DetailPhotoViewModel>(photoDto); return(View(photoView)); } else { return(Content("You don`t have anought permissions!")); } }