public InvoiceSaveReturn OnEdit(eStoreDbContext db, EditOrderDTO sales, int StoreId = 1) { Customer cust = db.Customers.Where(c => c.MobileNo == sales.MobileNo).FirstOrDefault(); if (cust == null) { string[] names = sales.Name.Split(" "); string FName = names[0]; string LName = ""; for (int i = 1; i < names.Length; i++) { LName += names[i] + " "; } cust = new Customer { City = "", Age = 30, FirstName = FName, Gender = Gender.Male, LastName = LName, MobileNo = sales.MobileNo, NoOfBills = 0, TotalAmount = 0, CreatedDate = DateTime.Now.Date }; db.Customers.Add(cust); db.SaveChanges(); } RegularInvoice inv = db.RegularInvoices.Find(sales.InvoiceNo); if (inv == null) { return(null); } inv.SaleItems = db.RegularSaleItems.Where(c => c.InvoiceNo == sales.InvoiceNo).ToList(); inv.PaymentDetail = db.PaymentDetails.Include(c => c.CardAmount).Where(c => c.InvoiceNo == sales.InvoiceNo).FirstOrDefault(); return(null);//TODO: temp }
public async Task <ActionResult <IEnumerable <GetDataDTO <EditOrderDTO> > > > ChangeOrderTransportationStatus( EditOrderDTO model) { if (!IsValidApiRequest()) { return(ApiBadRequest("Invalid Headers!")); } var user = await GetCurrentUser(); switch (user.Department) { case DepartmentId.Warehouse: if (model.Status == OrderStatusId.Delivering || model.Status == OrderStatusId.Delivered) { return(NotAllowedError("This action is not allowed!")); } break; case DepartmentId.Transportation: if (model.Status < OrderStatusId.Delivering) { return(NotAllowedError("This action is not allowed!")); } break; default: return(NotAllowedError("This action is not allowed!")); } var order = Context.Order.First(x => x.Id == model.OrderID); Context.Entry(order).Reference(x => x.Warehouse).Load(); var products = await Context.ProductBalances.Where(x => x.Order.Id == order.Id).Include(m => m.Medicament) .ToListAsync(); var productsWarehouse = await Context.ProductBalances.Where(pb => pb.Warehouse.Id == order.Warehouse.Id) .Include(m => m.Medicament).ToListAsync(); if (model.Status == OrderStatusId.Canceled || model.Status == OrderStatusId.Prepared) { foreach (var pr in products) { foreach (var prW in productsWarehouse) { if (pr.Medicament.Id == prW.Medicament.Id) { if (model.Status == OrderStatusId.Canceled) { prW.Quantity += pr.Quantity; } else { prW.Quantity -= pr.Quantity; } Context.ProductBalances.Update(prW); break; } } } } order.Status = model.Status; Context.Order.Update(order); await Context.SaveChangesAsync(); return(Ok()); }