Ejemplo n.º 1
0
        public ActionResult Edit(int?id, AutorViewModel model)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var modelAutor = new AutorViewModel();

            modelAutor.Id = id.Value;

            try
            {
                if (ModelState.IsValid)
                {
                    var entityOld   = db.Autores.Find(model.Id);
                    var modelUpdate = Mapper.Map <AutorViewModel, Autor>(model, entityOld);
                    db.Entry(modelUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(PartialView("_AutorDetalhe", modelAutor));
            }
            catch
            {
                return(PartialView("_AutorDetalhe", modelAutor));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutToDo([FromRoute] int id, [FromBody] ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(toDo).State = EntityState.Modified;

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

            return(NoContent());
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (id != employee.EmployeeId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IActionResult DeleteEstado(long id, IFormCollection form)
        {
            Estado estado = context.Set <Estado>().SingleOrDefault(c => c.Id == id);

            context.Entry(estado).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public IActionResult DeleteBook(long id, FormCollection form)
        {
            Books book = context.Set <Books>().SingleOrDefault(c => c.Id == id);

            context.Entry(book).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public IActionResult DeleteCustomer(long id, FormCollection form)
        {
            Customer customer = context.Set <Customer>().SingleOrDefault(c => c.Id == id);

            context.Entry(customer).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public IActionResult DeletePaciente(long id, IFormCollection form)
        {
            Paciente paciente = context.Set <Paciente>().SingleOrDefault(c => c.Id == id);

            context.Entry(paciente).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,Nome")] Restaurante restaurante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurante));
 }
 public ActionResult Edit([Bind(Include = "SolicitacaoCompraId,DataSolicitacao,UsuarioSolicitante,DeptoSolicitante,Quantidade,DataLimiteRecebimento,StatusSolicitacao,ProdutoId")] SolicitacaoCompra solicitacaoCompra)
 {
     if (ModelState.IsValid)
     {
         db.Entry(solicitacaoCompra).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProdutoId = new SelectList(db.Produto, "ProdutoId", "NomeProduto", solicitacaoCompra.ProdutoId);
     return(View(solicitacaoCompra));
 }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "ID,Nome,Preco,RestauranteID")] Prato prato)
 {
     if (ModelState.IsValid)
     {
         db.Entry(prato).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RestauranteID = new SelectList(db.Restaurante, "ID", "Nome", prato.RestauranteID);
     return(View(prato));
 }
Ejemplo n.º 11
0
        public virtual TEntity Update(TEntity obj)
        {
            // EntityFramework doesn't have "update" method, then it must be implemented
            var entry = Db.Entry(obj);

            DbSet.Attach(obj);
            entry.State = EntityState.Modified;
            //SaveChanges();

            return(obj);
        }
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(product).State = EntityState.Modified;
                _db.SaveChanges();

                return(RedirectToAction("Main"));
            }

            return(new HttpStatusCodeResult(400));
        }
Ejemplo n.º 13
0
 public JsonResult update(Student student)
 {
     if (ModelState.IsValid)
     {
         context.Entry(student).State = EntityState.Modified;
         context.SaveChanges();
         return(Json(new { success = true, data = student }));
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Ejemplo n.º 14
0
 bool IClienteRepositorio.Alterar(Cliente cliente)
 {
     try
     {
         _db.Entry(cliente).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch (Exception ex) // gravar em log
     {
         return(false);
     }
 }
Ejemplo n.º 15
0
        public JsonResult DeleteCustomer([FromBody] Customer Customer)
        {
            var customer = _context.Customer.Find(Customer.Id);

            _context.Entry(customer).Collection(c => c.Sale).Load();
            if (customer.Sale.Count > 0)
            {
                foreach (var sales in customer.Sale)
                {
                    _context.Sale.Remove(sales);
                }
            }
            _context.Customer.Remove(customer);
            _context.SaveChanges();

            return(Json(Customer));
        }
Ejemplo n.º 16
0
        public JsonResult DeleteStore(int id, [FromBody] Store Store)
        {
            var store = _context.Store.Find(Store.Id);

            _context.Entry(store).Collection(c => c.Sale).Load();
            if (store.Sale.Count > 0)
            {
                foreach (var sales in store.Sale)
                {
                    _context.Sale.Remove(sales);
                }
            }
            _context.Store.Remove(store);
            _context.SaveChanges();

            return(Json("Store Removed Successfully"));
        }
Ejemplo n.º 17
0
        public JsonResult DeleteProduct([FromBody] Product Product)
        {
            var product = _context.Product.Find(Product.Id);

            _context.Entry(product).Collection(c => c.Sale).Load();
            if (product.Sale.Count > 0)
            {
                foreach (var sales in product.Sale)
                {
                    _context.Sale.Remove(sales);
                }
            }
            _context.Product.Remove(product);
            _context.SaveChanges();

            return(Json("Product Removed Successfully"));
        }
Ejemplo n.º 18
0
        public ActionResult Register(StudentModel studentModel)
        {
            try
            {
                CRUDContext db = new CRUDContext();
                if (studentModel.Id > 0)
                {
                    Student student = db.Students.Include(x => x.Address).Where(x => x.Id == studentModel.Id).FirstOrDefault();
                    student.Email = studentModel.Email;
                    student.Name  = studentModel.Name;



                    db.Entry(student).State = EntityState.Modified;
                }
                else
                {
                    db.Students.Add(StudentMapper.ModelToContext(studentModel));
                }
                db.SaveChanges();
                var students = new CRUDContext().Students.Include(x => x.Address).ToList();
                List <StudentModel> studentModels = new List <StudentModel>();
                foreach (Student s in students)
                {
                    studentModels.Add(StudentMapper.ContextToModel(s));
                }

                return(Json(studentModels, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(e.Message, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 19
0
 public void Update(T model)
 {
     db.Entry <T>(model).State = EntityState.Modified;
 }
Ejemplo n.º 20
0
 public void Update(T oldEntity, T newEntity)
 {
     context.Entry(oldEntity).CurrentValues.SetValues(newEntity);
 }