Exemple #1
0
        public ActionResult Edit(int id, ImagesEditViewModels model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int categoryId;
                    var imageHelper = new PicPopImagesHelper();
                    PicPopImage image = imageHelper.FindById(id);

                    // Check if the image exist and if the image is relationship with the user
                    if (image == null || !image.UserId.Equals(User.Identity.GetUserId()))
                        return RedirectToAction("Index");

                    image.Name = model.Name;
                    image.Amount = model.Amount;
                    image.DtModified = DateTime.Now;
                    image.UserId = User.Identity.GetUserId();

                    if (!int.TryParse(model.CategoryId, out categoryId))
                        categoryId = 0;
                    image.CategoryId = categoryId == 0 ? (int?) null : categoryId;

                    imageHelper.Update(image);

                    return RedirectToAction("MyImages");
                }
                return View(model);
            }
            catch
            {
                return View();
            }
        }
Exemple #2
0
        public ActionResult Edit(int id)
        {
            var imageHelper = new PicPopImagesHelper();
            PicPopImage image = imageHelper.Details(id);

            // Check if the image exist and if the image is relationship with the user
            if (image == null || !image.UserId.Equals(User.Identity.GetUserId()))
                return RedirectToAction("Index");

            ImagesEditViewModels model = new ImagesEditViewModels()
            {
                Name = image.Name,
                Amount = image.Amount,
                CategoryId = image.CategoryId.ToString(),
                Categories = PicPop.Helper.CategoriesHelper.GetCategoriesSelectedItems(),
                //Blob = CloudStorageManagerHelper.GetUrlInfo(BlobFileType.ImagesOriginal, image.BlobFiles.First().BlobKey)
                Blob = CloudStorageManagerHelper.GetUrlInfo(image.BlobFiles.First())
            };

            return View(model);
        }