Exemplo n.º 1
0
        public bool UpdateBook(BookModel model)
        {
            if (model.Id == 0)
            {
                return(false);
            }

            var book = _context.Books.Single(b => b.Id == model.Id);

            _mapper.Map(model, book);
            _context.Entry(book).State = EntityState.Modified;

            return(_context.SaveChanges() != 0);
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PutPrestamo(int id, Prestamo prestamo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != prestamo.IdLector)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PrestamoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public IHttpActionResult Putbook(int id, book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!bookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public IHttpActionResult PutLibaryEntity(int id, LibaryEntity libaryEntity)
        {
            using (LibraryEntities db = new LibraryEntities())
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (id != libaryEntity.ID)
                {
                    return(BadRequest());
                }

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

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (db.LibaryEntity.Include(x => x.Type).Include(x => x.Category).SingleOrDefault(x => x.ID == id) == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
        public async Task <IHttpActionResult> EditLivros(int id, Livros livros)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != livros.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LivrosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public void Update(Reader obj)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         db.Reader.Attach(obj);
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public ActionResult Extend([Bind(Include = "RentID,DateEnd")] Rent rent)
        {
            Rent oldRent = db.Rents.Find(rent.RentID);

            if (oldRent == null)
            {
                return(HttpNotFound());
            }
            if (oldRent.DateEnd >= rent.DateEnd)
            {
                ViewBag.Errors = "The new date should be bigger than the last one.";
                return(View(oldRent));
            }
            oldRent.DateEnd = rent.DateEnd;

            db.Entry(oldRent).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "editorial_id,editorial_nombre")] Editorial editorial)
 {
     if (ModelState.IsValid)
     {
         db.Entry(editorial).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(editorial));
 }
 public ActionResult Edit([Bind(Include = "l_id,l_name,l_password")] Librarian librarian)
 {
     if (ModelState.IsValid)
     {
         db.Entry(librarian).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(librarian));
 }
Exemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "administrador_id,administrador_nombre,administrador_usuario,administrador_password,administrador_email")] Administrador administrador)
 {
     if (ModelState.IsValid)
     {
         db.Entry(administrador).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(administrador));
 }
Exemplo n.º 11
0
 public ActionResult Edit([Bind(Include = "genero_id,genero_nombre")] Genero genero)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genero).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genero));
 }
Exemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "AuthorID,LastName,FirstName")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
Exemplo n.º 13
0
 public ActionResult Edit([Bind(Include = "PublisherID,Name")] Publisher publisher)
 {
     if (ModelState.IsValid)
     {
         db.Entry(publisher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(publisher));
 }
Exemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "autor_id,autor_nombre")] Autor autor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(autor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(autor));
 }
 public void ChangeAvailability(Book obj)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         obj.isAvailable = !(obj.isAvailable);
         db.Book.Attach(obj);
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "ciudad_id,ciudad_nombre")] Ciudad ciudad)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ciudad).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ciudad));
 }
Exemplo n.º 17
0
 public void BookReturned(Loan obj)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         obj.dateReturn = DateTime.Now;
         db.Loan.Attach(obj);
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 18
0
 public ActionResult Edit([Bind(Include = "CustomerId,CustomerName,CustomerAddress,CustomerContact")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "CustomerID,CNP,FirstName,LastName,UserId")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "BookId,BookTitle,SerialNumber,CategoryId")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Category, "CategoryId", "CategoryName", book.CategoryId);
     return(View(book));
 }
 public ActionResult Edit([Bind(Include = "ejemplar_id,ejemplar_numero,ejemplar_estado,libro_id")] Ejemplar ejemplar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ejemplar).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.libro_id = new SelectList(db.Libroes, "libro_id", "libro_nombre", ejemplar.libro_id);
     return(View(ejemplar));
 }
 public ActionResult Edit([Bind(Include = "proveedor_id,proveedor_nombre,proveedor_telefono,proveedor_direccion,ciudad_id")] Proveedor proveedor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(proveedor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ciudad_id = new SelectList(db.Ciudads, "ciudad_id", "ciudad_nombre", proveedor.ciudad_id);
     return(View(proveedor));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "cliente_id,cliente_name,cliente_cedula,cliente_telefono,ciudad_id")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ciudad_id = new SelectList(db.Ciudads, "ciudad_id", "ciudad_nombre", cliente.ciudad_id);
     return(View(cliente));
 }
Exemplo n.º 24
0
 public ActionResult Edit(Author author)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(author).State = EntityState.Modified;
         _db.SaveChanges();
         TempData["message"] = $"Update author successfully!";
         return(RedirectToAction("Index", new { key = author.ID + " " + author.AuthorName }));
     }
     return(View(author));
 }
 public ActionResult Edit([Bind(Include = "prestamo_id,prestamo_fecha_desde,prestamo_fecha_hasta,prestamo_fecha_entrega,prestamo_estado_devolucion,prestamo_estado,cliente_id")] Prestamo prestamo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(prestamo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.cliente_id = new SelectList(db.Clientes, "cliente_id", "cliente_name", prestamo.cliente_id);
     return(View(prestamo));
 }
 public ActionResult Edit(Member member)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(member).State = EntityState.Modified;
         _db.SaveChanges();
         TempData["message"] = $"Update members successfully!";
         return(RedirectToAction("Index", new { key = member.ID + " " + member.FullName }));
     }
     return(View(member));
 }
Exemplo n.º 27
0
 public ActionResult Edit(BookCategory category)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(category).State = EntityState.Modified;
         _db.SaveChanges();
         TempData["message"] = $"Update author successfully!";
         return(RedirectToAction("Index", new { key = category.ID + " " + category.CategoryName }));
     }
     return(View(category));
 }
Exemplo n.º 28
0
 public ActionResult Edit([Bind(Include = "eje_prestamo_id,ejemplar_id,prestamo_id")] EjemplarPrestamo ejemplarPrestamo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ejemplarPrestamo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ejemplar_id = new SelectList(db.Ejemplars, "ejemplar_id", "ejemplar_numero", ejemplarPrestamo.ejemplar_id);
     ViewBag.prestamo_id = new SelectList(db.Prestamoes, "prestamo_id", "prestamo_estado_devolucion", ejemplarPrestamo.prestamo_id);
     return(View(ejemplarPrestamo));
 }
Exemplo n.º 29
0
 public ActionResult Edit([Bind(Include = "CopyID,BookID,PublisherID,Pages")] BookCopy bookCopy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookCopy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "Books", new { id = bookCopy.BookID }));
     }
     ViewBag.BookID      = new SelectList(db.Books, "BookID", "Name", bookCopy.BookID);
     ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", bookCopy.PublisherID);
     return(View(bookCopy));
 }
Exemplo n.º 30
0
        public async Task <HttpResponseMessage> PutEstudiante(int id, Estudiante estudiante)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != estudiante.IdLector)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResult()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = string.Format("El campo clave de la entidad debe ser igual a {0}", id)
                }));
            }

            if (EstudianteExists(id))
            {
                //    Estudiante record = await db.Estudiante.FindAsync(id);
                //    record.Nombre = estudiante.Nombre;
                //    record.Direccion = estudiante.Direccion;
                //    record.CI = estudiante.CI;
                //    record.Carrera = estudiante.Carrera;
                //    record.Edad = estudiante.Edad;

                db.Entry(estudiante).State = EntityState.Modified;
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, new BaseResult()
                    {
                        ExceptionDetail = ex,
                        StatusCode = HttpStatusCode.InternalServerError,
                        Message = "Ocurrió un error en la operación"
                    }));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new BaseResult()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = string.Format("No se encontró registro con el id {0}", id)
                }));
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }