Beispiel #1
0
        public ActionResult Edit(WriterView writerView)
        {
            bool   photoExist = true;
            string count      = string.Empty;
            string lastPhoto  = writerView.Photo;
            int    i          = 0;

            if (ModelState.IsValid)
            {
                string picture = writerView.Photo;
                string folder  = "~/Content/Photos/Writers";
                if (writerView.PhotoFile != null)
                {
                    while (photoExist)
                    {
                        i++;
                        count      = Convert.ToString(i);
                        photoExist = System.IO.File.Exists(Server.MapPath($"{folder}/{count}{writerView.PhotoFile.FileName}"));
                    }

                    if (count == "0")
                    {
                        count = string.Empty;
                    }

                    picture = FilesHelper.UploadPhoto(writerView.PhotoFile, folder, count);
                    picture = string.Format($"{folder}/{count}{picture}");
                }

                Writer writer = ToWriter(writerView);
                writer.Photo = picture;

                if (lastPhoto != picture && lastPhoto != "~/Content/Photos/Writers/Default.gif")
                {
                    DeletePhoto(lastPhoto);
                }

                db.Entry(writer).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "El escritor/a no puede ser guardado/a porque existe un/a con el mismo nombre.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            return(View(writerView));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "Id,Author,Title,Publisher,PublishingDate,Isbn,BorrowDate,ReturnDate,ReaderId")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReaderId = new SelectList(db.Readers, "ID", "Name", book.ReaderId);
     return(View(book));
 }
        public ActionResult Edit(BookType bookType)
        {
            if (ModelState.IsValid)
            {
                db.Entry(bookType).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "El género no puede ser guardado porque existe uno con el mismo nombre.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            return(View(bookType));
        }
Beispiel #4
0
 public ActionResult Edit(Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Surname,Street,HouseNumber,ApartmentNumber,PostalCode,City,PhoneNumber,Email")] Reader reader)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reader).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(reader));
 }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "BookId,ISBN,WriterId,BookTypeId,Title,Edition,Plot,DateOfRelease")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookTypeId = new SelectList(db.BookTypes, "BookTypeId", "Description", book.BookTypeId);
     ViewBag.WriterId   = new SelectList(db.Writers, "WriterId", "Name", book.WriterId);
     return(View(book));
 }
Beispiel #7
0
        public ActionResult Edit(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
        {
            try
            {
                db.Entry(role).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #8
0
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     _dbContext.SaveChanges();
 }