public Cheques Insert(Cheques model) { model.Id = Guid.NewGuid().ToString(); db.Cheques.Add(model); db.SaveChanges(); return(model); }
/// <summary> /// Permite guardar un producto. /// </summary> /// <param name="Product">Objeto producto con sus datos</param> /// <returns>Si no hay ningún problema al guardar, este retorna el UNIQUEID generado al producto.</returns> public ProductEntity Save(ProductEntity Product) { //Validando datos this.Validation(Product); //Validando Código var pExist = this.Find(Product.ProductCode); if (pExist != null) // Si existe, entra { throw new Exception("Ya existe un producto con este Código"); } using (var db = new ModelDb()) { Product.ProductID = Guid.NewGuid(); Product.ProductIsActive = true; //guardar producto db.Products.Add(Product); db.SaveChanges(); } return(Product); }
public SalesOrderDetails Insert(SalesOrderDetails model) { var product = productService.Find(x => x.ProductName == model.ProductName); model.Sku = product.SKU; model.PurchaseAmount = product.PurchaseAmount; model.SellingPrice = product.SellingAmount; model.Id = Guid.NewGuid().ToString(); db.SalesOrderDetails.Add(model); var so = db.SalesOrders.FirstOrDefault(x => x.Id == model.SalesOrderId); db.SaveChanges(); so.TotalAmount = db.SalesOrderDetails.Where(x => x.SalesOrderId == model.SalesOrderId).Sum(x => x.SubTotal ?? 0); db.SaveChanges(); return(model); }
public ActionResult Create(Photo photo, HttpPostedFileBase image) { try { photo.CreatedDate = DateTime.Now; if (!ModelState.IsValid) { return(View(photo)); } if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } db.Photos.Add(photo); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public void Update(T entity) { using (var db = new ModelDb()) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult Index() { var roles = new Models.UserRoles(); roles.Id = Guid.NewGuid().ToString(); roles.Name = ""; ModelDb db = new ModelDb(); db.UserRoles.Add(roles); db.SaveChanges(); return(View()); }
/// <summary> /// Permite guardar un cliente. /// </summary> /// <param name="Customer">Objeto cliente con sus datos</param> /// <returns>Si no hay ningún problema al guardar, este retorna el UNIQUEID generado al cliente.</returns> public Guid Save(CustomerEntity Customer) { using (var db = new ModelDb()) { Customer.CustomerID = Guid.NewGuid(); Customer.CustomerIsActive = true; //Guardamos el cliente db.Customers.Add(Customer); db.SaveChanges(); } return(Customer.CustomerID); }
public MarkEntity Save(MarkEntity Mark) { this.Validation(Mark); using (var db = new ModelDb()) { Mark.MarkID = Guid.NewGuid(); db.Marks.Add(Mark); db.SaveChanges(); return(Mark); } }
public void Delete(Guid ProductID) { using (var db = new ModelDb()) { var Product = this.Find(ProductID); if (Product != null) { Product.ProductIsActive = false; db.Entry(Product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public void Delete(Guid CustomerID) { using (var db = new ModelDb()) { var Customer = this.Find(CustomerID); if (Customer != null) { Customer.CustomerIsActive = false; db.Entry(Customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public LineEntity Save(LineEntity Line) { this.Validation(Line); using (var db = new ModelDb()) { Line.LineID = Guid.NewGuid(); db.Lines.Add(Line); db.SaveChanges(); return(Line); } }
public SalesOrders Insert(SalesOrders salesOrders) { try { db.SalesOrders.Add(salesOrders); db.SaveChanges(); } catch (Exception e) { } return(salesOrders); }
public void Edit(ProductEntity Product) { //Validando datos this.Validation(Product); using (var db = new ModelDb()) { //Se carga el producto var p = db.Products.Where(c => c.ProductID == Product.ProductID).FirstOrDefault(); //Se verifica que existe if (p != null) { //Validando Código var pExist = this.Find(Product.ProductCode); if (pExist != null) // Si existe, entra { if (pExist.ProductID != p.ProductID) { throw new Exception("Ya existe un producto con este Código"); } } //Se editan los datos p.ProductCode = Product.ProductCode; p.ProductName = Product.ProductName; p.ProductPrice = Product.ProductPrice; p.ProductDescription = Product.ProductDescription; p.MarkID = Product.MarkID; p.LineID = Product.LineID; //Se prepara para la edición db.Entry(p).State = System.Data.Entity.EntityState.Modified; //Se guardan los datos db.SaveChanges(); } } }
public void Save() { context.SaveChanges(); }
public void Save() { _db.SaveChanges(); }