Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public ProductCategory CreateProductCategory(string categoryName)
        {
            try {
                if (string.IsNullOrEmpty(categoryName))
                {
                    return(null);
                }

                var productCategory = new ProductCategory()
                {
                    CategoryName = categoryName
                };

                using (var context = new TakeThaiContext())
                {
                    context.Add(productCategory);
                    context.SaveChanges();
                }

                return(productCategory);
            } catch
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public ProductModels UpdateProductModels(ProductModels productModels)
        {
            try
            {
                using (var context = new TakeThaiContext())
                {
                    context.Update(productModels);
                    context.SaveChanges();
                }

                return(productModels);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public List <EndOfDaySubModels> GenerateEndOfDaySubModels(EndOfDayModel endOfDayModel)
        {
            var endOfDaySubModels = new List <EndOfDaySubModels>();

            if (endOfDayModel == null || endOfDayModel.Id < 0 || endOfDayModel.DateRequested == null)
            {
                return(endOfDaySubModels);
            }

            using (var context = new TakeThaiContext())
            {
                List <OrderModels> allOrders;

                if (endOfDayModel.ReportType.ToLowerInvariant() == "all")
                {
                    allOrders = context.OrderModels.Where(x => x.OrderReceivedDate.Date == endOfDayModel.DateRequested.Date).ToList();
                }
                else
                {
                    allOrders = context.OrderModels.Where(x => x.OrderReceivedDate.Date == endOfDayModel.DateRequested.Date && x.PaymentMethod == endOfDayModel.ReportType).ToList();
                }

                if (endOfDayModel.OrderType.ToLowerInvariant() != "all")
                {
                    allOrders.Where(x => x.DeliveryOrCollection == endOfDayModel.OrderType).ToList();
                }

                foreach (var order in allOrders)
                {
                    var endOfDaySubModel = new EndOfDaySubModels
                    {
                        EndOfDayModel = endOfDayModel,
                        OrderTotal    = order.TotalCost,
                        OrderType     = order.DeliveryOrCollection,
                        PaymentMethod = order.PaymentMethod
                    };

                    context.Add(endOfDaySubModel);
                    context.SaveChanges();

                    endOfDaySubModels.Add(endOfDaySubModel);
                }
            }

            return(endOfDaySubModels);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public string RemoveOrder(int orderId)
        {
            try
            {
                if (orderId <= 0)
                {
                    return(null);
                }

                string message = string.Empty;

                using (var context = new TakeThaiContext())
                {
                    var order = context.OrderModels
                                .Include(o => o.CustomerDeliveryAddressModel)
                                .Include(o => o.SubOrderModelsList)
                                .FirstOrDefault(o => o.Id == orderId);

                    if (order != null)
                    {
                        context.Remove(order);
                        context.SaveChanges();

                        message = "Order has been successfully removed.";
                    }
                    else
                    {
                        message = "Cannot find Order.";
                    }
                }

                return(message);
            }
            catch (Exception exception)
            {
                return($"An unexpected error occurred. {exception.Message}");
            }
        }
Exemplo n.º 10
0
        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}");
            }
        }
Exemplo n.º 11
0
        public OrderModels CreateNewOrder(DateTime orderReceivedDate, int operatorModelId, string deliveryMethod, string paymentMethod, int deliveryAddressId, int customerId, double deliveryCharge)
        {
            try
            {
                using (var context = new TakeThaiContext())
                {
                    var order = new OrderModels()
                    {
                        OrderPlacedDate      = DateTime.Now,
                        OrderReceivedDate    = orderReceivedDate,
                        DeliveryOrCollection = deliveryMethod,
                        PaymentMethod        = paymentMethod,
                        CustomerModels       = context.CustomerModels.FirstOrDefault(c => c.Id == customerId),
                        DeliveryCost         = deliveryCharge
                    };

                    if (deliveryMethod == "Delivery")
                    {
                        if (deliveryAddressId == 0)
                        {
                            if (order.CustomerModels != null)
                            {
                                var newDeliveryAddress = new CustomerDeliveryAddressModel
                                {
                                    AddressLine1 = order.CustomerModels.AddressLine1,
                                    AddressLine2 = order.CustomerModels.AddressLine2,
                                    AddressLine3 = order.CustomerModels.AddressLine3,
                                    PostalCode   = order.CustomerModels.PostalCode
                                };

                                order.CustomerDeliveryAddressModel = newDeliveryAddress;
                            }
                        }
                        else if (deliveryAddressId > 0)
                        {
                            var deliveryAddress = context.CustomerAltAddressModels.FirstOrDefault(c => c.Id == deliveryAddressId);
                            if (deliveryAddress != null)
                            {
                                var newDeliveryAddress = new CustomerDeliveryAddressModel
                                {
                                    AddressLine1 = deliveryAddress.AddressLine1,
                                    AddressLine2 = deliveryAddress.AddressLine2,
                                    AddressLine3 = deliveryAddress.AddressLine3,
                                    PostalCode   = deliveryAddress.PostalCode
                                };

                                order.CustomerDeliveryAddressModel = newDeliveryAddress;
                            }
                        }
                    }

                    order.OperatorModels = context.OperatorModels.FirstOrDefault(op => op.Id == operatorModelId);

                    context.Add(order);
                    context.SaveChanges();

                    return(order);
                }
            }
            catch
            {
                return(null);
            }
        }