Exemple #1
0
        //// GET: Gallery/Edit/5
        //public ViewResult Edit(int? id)
        //{
        //    if (id == null)
        //    {
        //     Response.StatusCode = 404;
        //     return View("NotFound", null);
        //    }

        //    var photo = photoService.GetById(id.GetValueOrDefault());

        //    if (photo == null)
        //    {
        //     Response.StatusCode = 404;
        //     return View("NotFound", id);
        //    }

        //    var model = new PhotoEditViewModel
        //    {
        //     Id = photo.Id,
        //     Title = photo.Title,
        //     //Tags = photo.Tags,
        //     ExistingPhotoPath = photo.PhotoPath
        //    };
        //    return View(model);
        //}

        //// POST: Gallery/Edit/5
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public IActionResult Edit(int id, [Bind("Id,Title,TagStr,Photo")] PhotoEditViewModel model)
        //{
        //    if (id != model.Id)
        //    {
        //        return NotFound();
        //    }

        //    if (ModelState.IsValid)
        //    {
        //        try
        //        {
        //         var photo = photoService.GetById(model.Id);
        //            photo.Title = model.Title;
        //         if (model.Photo != null)
        //            {
        //             if (model.ExistingPhotoPath != null)
        //             {
        //              string filePath = Path.Combine(hostEnvironment.WebRootPath,
        //               "images", model.ExistingPhotoPath);
        //              System.IO.File.Delete(filePath);
        //             }
        //             photo.PhotoPath = ProcessUploadedFile(model);

        //            }
        //            photoService.Update(photo);

        //            var tags = tagService.GetByPhotoId(model.Id);
        //            foreach (var tag in tags)
        //            {
        //             tagService.Update(tag);
        //            }

        //        }
        //        catch (DbUpdateConcurrencyException)
        //        {
        //         if (!PhotoExists(model.Id))
        //            {
        //                return NotFound();
        //            }

        //         throw;
        //        }
        //        return RedirectToAction(nameof(Index));
        //    }
        //    return View(model);
        //}

        // GET: Gallery/Delete/5
        public ViewResult Delete(int?id)
        {
            if (id == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound", null));
            }

            var photo = photoService.GetById(id.GetValueOrDefault());

            if (photo == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound", null));
            }

            var model = new PhotoDeleteViewModel
            {
                Id                = photo.Id,
                Title             = photo.Title,
                ExistingPhotoPath = photo.PhotoPath,
            };

            return(View(model));
        }
Exemple #2
0
        public ActionResult Delete(int id)
        {
            var photo = photoAPI.FindPhotoById(id);

            if (photo == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var model = new PhotoDeleteViewModel
                {
                    Photo = photo.ToDetailsViewModel()
                };

                return(View(model));
            }
        }