예제 #1
0
        public ActionResult AddPhoto(PhotoViewModel viewModel, HttpPostedFileBase uploadImage, string photoName, int page = 1)
        {
            if (ModelState.IsValid)
            {
                if (uploadImage == null)
                {
                    ModelState.AddModelError("", "A photo is not selected.");
                    return(View(viewModel));
                }

                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }

                viewModel.Image        = imageData;
                viewModel.CreationDate = DateTime.Now;
                viewModel.UserId       = userService.GetUserEntityByLogin(User.Identity.Name).Id;
                photoService.CreateEntity(viewModel.ToBllPhoto());

                return(RedirectToAction("Photos", new { page = page, photoName = photoName }));
            }
            return(View(viewModel));
        }
        public ActionResult CreatePhoto(PhotoViewModel photo, IEnumerable <HttpPostedFileBase> files, string Id)
        {
            if (!ModelState.IsValid)
            {
                return(View(photo));
            }
            if (files.Count() == 0 || files.FirstOrDefault() == null)
            {
                ViewBag.error = "Please choose a file";
                return(View(photo));
            }

            PhotoViewModel model = new PhotoViewModel();

            foreach (var file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    model.Image = Images.GetImageNewSize(file);
                }

                model.Description = photo.Description;
                model.CreatedOn   = DateTime.Now;
                model.CategoryId  = Convert.ToInt32(Id);
                model.UserId      = userService.GetUserByEmail(User.Identity.Name).UserId;
                photoService.CreatePhoto(model.ToBllPhoto());
            }

            return(RedirectToAction("GetPhotoForUser"));
        }
        public ActionResult EditPhoto(PhotoViewModel photo, int photoId, int id)
        {
            if (ModelState.IsValid)
            {
                photo.Id         = photoId;
                photo.CategoryId = id;
                photoService.UpdatePhoto(photo.ToBllPhoto());
                TempData["message"] = string.Format("Photo {0}  has been updated.", photo.Description);
                return(RedirectToAction("GetPhotoForUser"));
            }

            return(View(photo));
        }
예제 #4
0
        public ActionResult EditPhoto(PhotoViewModel viewModel, string photoName, int page = 1)
        {
            PhotoViewModel photo = photoService.GetEntity(viewModel.Id).ToMvcPhoto();

            if (photo == null)
            {
                return(RedirectToAction("Photos"));
            }

            if (ModelState.IsValid)
            {
                photo.Name        = viewModel.Name;
                photo.Description = viewModel.Description;
                photoService.UpdateEntity(photo.ToBllPhoto());
                return(RedirectToAction("Photos",
                                        new { userName = User.Identity.Name, page = page, currentPhotoId = photo.Id, photoName = photoName }));
            }
            return(View(photo));
        }
예제 #5
0
        public ActionResult CreatePhoto(PhotoViewModel photo, HttpPostedFileBase upload)
        {
            if (upload == null)
            {
                ModelState.AddModelError("", "Photo haven't been loaded yet");
            }

            if (ModelState.IsValid)
            {
                using (var binaryreader = new BinaryReader(upload.InputStream))
                {
                    photo.Image = binaryreader.ReadBytes(upload.ContentLength);
                }
                var user = accountService.GetUserByUserName(HttpContext.User.Identity.Name);
                photo.UserId        = user.Id;
                photo.DateOfLoading = DateTime.Now;
                photoService.Create(photo.ToBllPhoto());
                return(RedirectToAction("UserPage", "Home"));
            }
            return(View(photo));
        }
예제 #6
0
 public ActionResult DeletePhoto(PhotoViewModel viewModel, string photoName, int page = 1)
 {
     photoService.DeleteEntity(viewModel.ToBllPhoto());
     return(RedirectToAction("Photos", new { page = page, photoName = photoName }));
 }