public ActionResult Save(Employee e) { try { if (e.EmployeeID != 0) { db.Employees.Attach(e); db.Entry(e).State = EntityState.Modified; } if (e.EmployeeID == 0) { db.Employees.Add(e); } db.SaveChanges(); var emps = (from emp in db.Employees select emp).ToList(); ViewBag.Empregados = emps; } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O Registro Foi Salvo com Sucesso"; return(View("New", new Employee())); }
public ActionResult Save(Product p) { try { if (p.ProductID != 0) { db.Products.Attach(p); db.Entry(p).State = EntityState.Modified; } if (p.ProductID == 0) { db.Products.Add(p); } db.SaveChanges(); ViewBag.produto = Products(); ViewBag.Categorias = Categories(); ViewBag.Products = Products(); } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O Registro Foi Salvo com Sucesso"; return(View("New", new Product())); }
public ActionResult SaveJson(Supplier e) { var resposta = new RespostaHtml { success = true }; try { if (e.SupplierID == 0) { db.Suppliers.Add(e); } else { db.Suppliers.Attach(e); db.Entry(e).State = EntityState.Modified; } db.SaveChanges(); resposta.Data = e; } catch (Exception ex) { ex = ErrorException(ex); resposta.success = false; resposta.message = ex.Message; } return(Json(resposta, JsonRequestBehavior.DenyGet)); }
public ActionResult Save(Employee e) { try { //Usar nossa classe de banco de dados. //Instanciando a base. var db = new NorthWind(); if (e.Adventista == null) { e.Adventista = false; } //ou e.Adventista = e.Adventista == null ? false : true; if (e.EmployeeID == 0) { //Como eu salvo um registro no Banco de Dados? db.Employees.Add(e); } else { db.Employees.Attach(e); db.Entry(e).State = EntityState.Modified; } db.SaveChanges(); var boss = (from emp in db.Employees select emp).ToList(); ViewBag.Empregados = boss; } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O registro foi incluido com sucesso!"; return(View("New", new Employee())); }
public ActionResult SaveJson(Supplier s) { var resposta = new RespostaHtml { success = true }; try { if (s.SupplierID == 0) { //Como eu salvo um registro no Banco de Dados? db.Suppliers.Add(s); } else { db.Suppliers.Attach(s); db.Entry(s).State = EntityState.Modified; } db.SaveChanges(); resposta.Data = s; } catch (Exception ex) { ex = ErrorException(ex); resposta.success = false; resposta.message = ex.Message; return(Json(resposta, JsonRequestBehavior.DenyGet)); } return(Json(resposta, JsonRequestBehavior.DenyGet)); }
public ActionResult Save(Employee e) { try { // Usar nossa classe de banco de dados e.Adventista = e.Adventista == null ? false : true; if (e.EmployeeID == 0) { // Como eu salvo um registro no Banco de Dados? db.Employees.Add(e); } else { db.Employees.Attach(e); db.Entry(e).State = EntityState.Modified; } db.SaveChanges(); ViewBag.Chefes = ObterChefes(); } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } // Se não ocorrer um erro, o que acontece? ViewBag.Message = "O Registro Foi Incluido com Sucesso!"; return(View("New", new Employee())); }
public IHttpActionResult PutCustomer(string id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.CustomerID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit(Customer customer) { try { db.Customers.Attach(customer); db.Entry(customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O registro foi alterado com sucesso"; return(View("Details", customer)); }
public ActionResult Edit(Customer customer) { try { //Como eu salvo um registro no Banco de Dados? db.Customers.Add(customer); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O registro foi incluido com sucesso!"; return(View("Details", customer)); }
public ActionResult Save(Product p) { try { var db = new NorthWind(); if (p.ProductID == 0) { db.Products.Add(p); } else { db.Products.Attach(p); db.Entry(p).State = EntityState.Modified; } db.SaveChanges(); var prdts = (from emp in db.Employees select emp).ToList(); var sup = (from emp in db.Suppliers select emp).ToList(); var cat = (from emp in db.Categories select emp).ToList(); ViewBag.Categorias = cat; ViewBag.Fornecedores = sup; ViewBag.Produtos = prdts; } catch (Exception ex) { ex = ErrorException(ex); return(View("Erro", ex)); } ViewBag.Message = "O registro foi incluido com sucesso!"; return(View("New", new Product())); }
public ActionResult SaveJson(Employee e) { var resposta = new RespostaHtml { success = true }; try { //Usar nossa classe de banco de dados. //Instanciando a base. var db = new NorthWind(); if (e.Adventista == null) { e.Adventista = false; } //ou e.Adventista = e.Adventista == null ? false : true; if (e.EmployeeID == 0) { //Como eu salvo um registro no Banco de Dados? db.Employees.Add(e); } else { db.Employees.Attach(e); db.Entry(e).State = EntityState.Modified; } db.SaveChanges(); resposta.Data = e; } catch (Exception ex) { ex = ErrorException(ex); resposta.success = false; resposta.message = ex.Message; return(Json(resposta, JsonRequestBehavior.DenyGet)); } return(Json(resposta, JsonRequestBehavior.DenyGet)); }