예제 #1
0
파일: OrderClass.cs 프로젝트: CW92/TakeThai
        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);
            }
        }
예제 #2
0
파일: OrderClass.cs 프로젝트: CW92/TakeThai
        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);
        }
예제 #3
0
파일: OrderClass.cs 프로젝트: CW92/TakeThai
        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);
            }
        }
예제 #4
0
        public ProductModels UpdateProductModels(ProductModels productModels)
        {
            try
            {
                using (var context = new TakeThaiContext())
                {
                    context.Update(productModels);
                    context.SaveChanges();
                }

                return(productModels);
            }
            catch
            {
                return(null);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
파일: OrderClass.cs 프로젝트: CW92/TakeThai
        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);
            }
        }
예제 #7
0
파일: OrderClass.cs 프로젝트: CW92/TakeThai
        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}");
            }
        }