예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
        public ProductModels CreateProductModels(ProductModels productModels)
        {
            try
            {
                using (var context = new TakeThaiContext())
                {
                    context.Add(productModels);
                    context.SaveChanges();
                }

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