Example #1
0
        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"));
        }
Example #2
0
        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));
        }
Example #3
0
        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!"));
            }
        }