Ejemplo n.º 1
0
        public ActionResult Create(Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string name = "";
                    if (Request.Files.Count == 1)
                        name = UploadHelper.SavePhotoToServer(Request.Files[0]);

                    if (ModelState.IsValid)
                    {
                        album.CoverPath = name;
                        unitOfWork.AlbumRepository.Insert(album);
                        unitOfWork.Save();

                        return RedirectToAction("Index");
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("File", ex);
            }

            return View(album);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string name = "";
                    if (Request.Files.Count == 1)
                        name = UploadHelper.UpdatePhotoToServer(
                            album.CoverPath,
                            Request.Files[0]);

                    album.CoverPath = name;
                    unitOfWork.AlbumRepository.Update(album);
                    unitOfWork.Save();

                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("File", ex);
            }

            ViewBag.State = "edit";
            ViewBag.Path = album.CoverPath ?? "";
            ViewBag.Name = album.Name ?? "";
            return View(album);
        }