public bool AddOrder(OrderViewModel objOrderViewModel) { Order objOrder = new Order(); objOrder.CustomerId = objOrderViewModel.CustomerId; objOrder.FinalTotal = objOrderViewModel.FinalTotal; objOrder.OrderDate = DateTime.Now; objOrder.OrderNumber = String.Format("{0:ddmmmyyyyhhmmss}", DateTime.Now); objOrder.PaymentTypeId = objOrderViewModel.PaymentTypeId; objInvoiceDbEntities.Orders.Add(objOrder); objInvoiceDbEntities.SaveChanges(); int OrderId = objOrder.OrderId; foreach (var item in objOrderViewModel.ListOfOrderDetailViewModel) { OrderDetail objOrderDetail = new OrderDetail(); objOrderDetail.OrderId = OrderId; objOrderDetail.Discount = item.Discount; objOrderDetail.ItemId = item.ItemId; objOrderDetail.Total = item.Total; objOrderDetail.UnitPrice = item.UnitPrice; objOrderDetail.Quantity = item.Quantity; objInvoiceDbEntities.OrderDetails.Add(objOrderDetail); objInvoiceDbEntities.SaveChanges(); Transaction objTransaction = new Transaction(); objTransaction.ItemId = item.ItemId; objTransaction.Quantity = (-1) * item.Quantity; objTransaction.TransactionDate = DateTime.Now; objTransaction.TypeId = 2; objInvoiceDbEntities.Transactions.Add(objTransaction); objInvoiceDbEntities.SaveChanges(); } return(true); }
public void addCustomer(Customer c) { if (c.Customer_No == 0) { c.Customer_No = db.Customers.ToList().Last().Customer_No; c.Customer_No = c.Customer_No + 1; } db.Customers.Add(c); db.SaveChanges(); }
public void addUser(User u) { var u_no = db.Users.ToList().Last(); if (u_no.user_no != null) { u.user_no = (u_no.user_no + 1); } else { u.user_no = 50; } db.Users.Add(u); db.SaveChanges(); }
public void AddComment(string comment, int id, int invo_id) { DateTime d = DateTime.Now.ToLocalTime(); Comment c = new Comment(); c.comment1 = comment; c.Date = d; c.User_id = id; c.Invoices_Id = invo_id; db.Comments.Add(c); db.SaveChanges(); }
public IHttpActionResult UpdateProduct(int id, [FromBody] Product prod) { if (ModelState.IsValid) { var ProductoExiste = dbContext.Products.Count(c => c.ProductID == id) > 0; if (ProductoExiste) { dbContext.Entry(prod).State = EntityState.Modified; dbContext.SaveChanges(); return(Ok()); } else { return(NotFound()); } } else { return(BadRequest()); } }
public void InsertInvoice(Invoice i) { db.Invoices.Add(i); db.SaveChanges(); }