//Delete Order public Boolean DeleteOrder(OrderViewModel ord) { using (Cobra db = new Cobra()) { var model2 = db.OrderDetails.SingleOrDefault(x => x.Id == ord.productDetailsId); model2.OrderId = ord.Id; model2.ProductId = ord.ProductId; db.Entry(model2).State = System.Data.Entity.EntityState.Detached; db.OrderDetails.Attach(model2); db.OrderDetails.Remove(model2); db.SaveChanges(); try { var model = db.OrderHeaders.SingleOrDefault(x => x.OrderId == ord.Id); model.OrderDate = ord.OrderDate; model.PersonId = ord.PersonId; db.Entry(model).State = System.Data.Entity.EntityState.Detached; db.OrderHeaders.Attach(model); db.OrderHeaders.Remove(model); db.SaveChanges(); }catch (Exception e) { return(false); } } return(true); }
//Delete People public Boolean DeletePerson(PersonViewModel person) { var people = new Person { Id = person.Id, Name = person.Name, Address1 = person.Address1, Address2 = person.Address2, City = person.City }; try { if (person != null) { var emp = _context.Entry(people); if (emp.State == System.Data.Entity.EntityState.Detached) { _context.People.Attach(people); _context.People.Remove(people); _context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception e) { return(false); } }
//Update People public Boolean UpdatePerson(PersonViewModel person) { var people = new Person { Id = person.Id, Name = person.Name, Address1 = person.Address1, Address2 = person.Address2, City = person.City }; if (people != null) { using (Cobra Obj = new Cobra()) { var emp = Obj.Entry(people); var result = Obj.People.Where(x => x.Id == person.Id).FirstOrDefault(); result.Name = person.Name; result.Address1 = person.Address1; result.Address2 = person.Address2; result.City = person.City; Obj.SaveChanges(); return(true); } } else { return(false); } }
//Update Order public Boolean upOrder(OrderViewModel ord) { using (Cobra Obj = new Cobra()) { var model = Obj.OrderHeaders.SingleOrDefault(x => x.OrderId == ord.OrderId); model.OrderDate = ord.OrderDate; model.PersonId = ord.PersonId; Obj.Entry(model).State = EntityState.Modified; Obj.SaveChanges(); var model2 = Obj.OrderDetails.SingleOrDefault(x => x.Id == ord.Id); model2.OrderId = ord.OrderId; model2.ProductId = ord.ProductId; Obj.Entry(model2).State = EntityState.Modified; Obj.SaveChanges(); return(true); } }