internal OrderModels UpdateQuantity(long subOrderId, int quantity) { if (subOrderId == 0) { return(null); } using (var context = new TakeThaiContext()) { var subOrder = context.SubOrderModels .Include(s => s.OrderModel) .FirstOrDefault(s => s.Id == subOrderId); if (subOrder != null) { subOrder.Quantity = quantity; context.Update(subOrder); context.SaveChanges(); var order = subOrder.OrderModel; var subOrders = context.SubOrderModels .Where(s => s.OrderModel == order) .Include(s => s.ProductSubModels) .ToList(); var subOrderModels = subOrders.ToList(); double totalPrice = 0; foreach (var getSubOrder in subOrderModels) { if (getSubOrder.Quantity == 0) { getSubOrder.Quantity = 1; } totalPrice += getSubOrder.Quantity * getSubOrder.ProductSubModels.Price; } totalPrice = Math.Round(totalPrice, 2, MidpointRounding.ToEven); if (order != null) { order.SubTotal = totalPrice; order.TotalCost = order.SubTotal + order.DeliveryCost - order.CustomerDiscount; context.Update(order); context.SaveChanges(); } return(order); } return(null); } }
public bool AddSpecialRequestToSubOrder(int subOrderId, List <int> specialRequestIds, string customText) { using (var context = new TakeThaiContext()) { var subOrder = context.SubOrderModels .Include(c => c.SubOrderSpecialRequestModel) .FirstOrDefault(s => s.Id == subOrderId); if (subOrder == null) { return(false); } var specialRequests = context.SpecialRequestOptionsPreConfiguredModels.Where(o => specialRequestIds.Contains(o.Id)).ToList(); var subOrderSpecialRequests = new List <SubOrderSpecialRequestModel>(); if (subOrder.SubOrderSpecialRequestModel.Count > 0) { subOrder.SubOrderSpecialRequestModel = new List <SubOrderSpecialRequestModel>(); context.Update(subOrder); } foreach (var special in specialRequests) { var subOrderSpecialRequestModel = new SubOrderSpecialRequestModel { SubOrderModels = subOrder, SpecialRequestOptionsPreConfiguredModel = special }; subOrderSpecialRequests.Add(subOrderSpecialRequestModel); } subOrder.SpecialCustomerNotes = customText; subOrder.SubOrderSpecialRequestModel = subOrderSpecialRequests; context.Update(subOrder); context.SaveChanges(); } return(true); }
public SubOrderModels CreateNewSubOrder(int orderId, int productSubModelId, int customerModelId, string specialNotes) { try { using (var context = new TakeThaiContext()) { var order = context.OrderModels.FirstOrDefault(o => o.Id == orderId); var subOrder = new SubOrderModels() { OrderModel = order, SpecialCustomerNotes = specialNotes }; subOrder.ProductSubModels = context.ProductSubModels.FirstOrDefault(p => p.Id == productSubModelId); subOrder.CustomerModels = context.CustomerModels.FirstOrDefault(c => c.Id == customerModelId); context.Add(subOrder); context.SaveChanges(); var subOrders = context.SubOrderModels .Where(s => s.OrderModel == order) .Include(s => s.ProductSubModels) .ToList(); var subOrderModels = subOrders.ToList(); double totalPrice = 0; foreach (var getSubOrder in subOrderModels) { if (getSubOrder.Quantity == 0) { getSubOrder.Quantity = 1; } totalPrice += getSubOrder.Quantity * getSubOrder.ProductSubModels.Price; } totalPrice = Math.Round(totalPrice, 2, MidpointRounding.ToEven); if (order != null) { order.SubTotal = totalPrice; order.TotalCost = order.SubTotal + order.DeliveryCost - order.CustomerDiscount; context.Update(order); context.SaveChanges(); } return(subOrder); } } catch { return(null); } }
public ProductModels UpdateProductModels(ProductModels productModels) { try { using (var context = new TakeThaiContext()) { context.Update(productModels); context.SaveChanges(); } return(productModels); } catch { return(null); } }
public bool MarkAsPrinted(int id) { using (var context = new TakeThaiContext()) { var endOfDayReport = context.EndOfDayModels.FirstOrDefault(x => x.Id == id); if (endOfDayReport == null) { return(false); } endOfDayReport.Printed = true; context.Update(endOfDayReport); context.SaveChanges(); return(endOfDayReport.Printed); } }
public OrderModels UpdateOrder(TotalOrderModel totalOrderModels) { using (var context = new TakeThaiContext()) { var orderModels = context.OrderModels.FirstOrDefault(c => c.Id == totalOrderModels.Id); if (orderModels != null) { orderModels.PaymentMethod = totalOrderModels.PaymentMethod; orderModels.VatReceipt = totalOrderModels.VatReceipt; context.Update(orderModels); context.SaveChanges(); } return(orderModels); } }
public string RemoveSubOrder(int orderId, int subOrderId) { try { if (orderId <= 0 || subOrderId <= 0) { return(null); } string message = string.Empty; using (var context = new TakeThaiContext()) { var subOrder = context.SubOrderModels.FirstOrDefault(s => s.Id == subOrderId); var order = context.OrderModels.FirstOrDefault(o => o.Id == orderId); if (order != null && subOrder != null) { order.SubOrderModelsList = context.SubOrderModels.Where(s => s.OrderModel == order).ToList(); if (order.SubOrderModelsList.Contains(subOrder)) { context.Remove(subOrder); context.SaveChanges(); var subOrders = context.SubOrderModels .Where(s => s.OrderModel == order) .Include(s => s.ProductSubModels) .ToList(); var subOrderModels = subOrders.ToList(); double totalPrice = 0; foreach (var getSubOrder in subOrderModels) { if (getSubOrder.Quantity == 0) { getSubOrder.Quantity = 1; } totalPrice += getSubOrder.Quantity * getSubOrder.ProductSubModels.Price; } totalPrice = Math.Round(totalPrice, 2, MidpointRounding.ToEven); if (order != null) { order.SubTotal = totalPrice; order.TotalCost = order.SubTotal + order.DeliveryCost - order.CustomerDiscount; context.Update(order); context.SaveChanges(); } message = "Sub Order has been successfully removed."; } else { message = "Cannot find Sub Order within the specified order."; } } else { message = "Cannot find Order or Sub Order."; } } return(message); } catch (Exception exception) { return($"An unexpected error occurred. {exception.Message}"); } }