Exemplo n.º 1
0
        public List <CustomerProductRequestsModels> GetAllSpecialProductRequests(string productName, string productOptionName)
        {
            var specialOptionRequests = new List <CustomerProductRequestsModels>();

            if (string.IsNullOrEmpty(productOptionName) || string.IsNullOrEmpty(productName))
            {
                return(specialOptionRequests);
            }

            using (var context = new TakeThaiContext())
            {
                var product = context.ProductModels.Where(p => p.Name.ToLower() == productName.ToLower()).FirstOrDefault();

                if (product == null)
                {
                    return(specialOptionRequests);
                }

                var productOption = context.ProductSubModels.Where(p => p.ProductModel.Id == product.Id && p.OptionName.ToLower() == productOptionName.ToLower()).FirstOrDefault();

                if (productOption != null)
                {
                    specialOptionRequests = context.CustomerProductRequestsModels.Where(po => po.ProductSubModels.Id == productOption.Id || po.ProductSubModels == null).ToList();
                }

                for (var i = 0; i < specialOptionRequests.Count(); i++)
                {
                    specialOptionRequests[i].ProductSubModels = null;
                }
            }

            return(specialOptionRequests);
        }
Exemplo n.º 2
0
 public List <EndOfDayModel> getAllEndOfDayModels()
 {
     using (var context = new TakeThaiContext())
     {
         return(context.EndOfDayModels.ToList());
     }
 }
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 SubOrderModels GetSubOrdersById(int id)
 {
     using (var context = new TakeThaiContext())
     {
         return(context.SubOrderModels
                .Include(s => s.ProductSubModels)
                .FirstOrDefault(s => s.Id == id));
     }
 }
Exemplo n.º 5
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.º 6
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.º 7
0
        public OrderModels GetOrderById(int id)
        {
            OrderModels orderModel = null;

            using (var context = new TakeThaiContext())
            {
                orderModel = context.OrderModels
                             .Include(o => o.SubOrderModelsList)
                             .FirstOrDefault(o => o.Id == id);
            }

            return(orderModel);
        }
Exemplo n.º 8
0
        public List <ProductModels> GetAllProducts()
        {
            var products = new List <ProductModels>();

            using (var context = new TakeThaiContext())
            {
                products = context.ProductModels
                           .Include(p => p.ProductSubModels)
                           .Include(p => p.ProductCategory)
                           .ToList();
            }

            return(products);
        }
Exemplo n.º 9
0
 public List <OrderModels> GetTodaysOrders()
 {
     using (var context = new TakeThaiContext())
     {
         return
             (context.OrderModels
              .Include(c => c.CustomerModels)
              .Include(c => c.CustomerDeliveryAddressModel)
              .Include(c => c.SubOrderModelsList)
              .ThenInclude(s => s.SubOrderSpecialRequestModel)
              .Where(c => c.OrderPlacedDate.Date == DateTime.Today)
              .OrderBy(c => c.Id)
              .ToList());
     }
 }
Exemplo n.º 10
0
 public ProductModels GetProductModels(int productId)
 {
     try
     {
         using (var context = new TakeThaiContext())
         {
             return(context.ProductModels
                    .FirstOrDefault(p => p.Id == productId));
         }
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 11
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.º 12
0
        public ProductModels UpdateProductModels(ProductModels productModels)
        {
            try
            {
                using (var context = new TakeThaiContext())
                {
                    context.Update(productModels);
                    context.SaveChanges();
                }

                return(productModels);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 13
0
        public List <OrderModels> GetAllOrders()
        {
            var orders = new List <OrderModels>();

            using (var context = new TakeThaiContext())
            {
                orders = context.OrderModels.ToList();
                for (var i = 0; i < orders.Count; i++)
                {
                    orders[i].SubOrderModelsList = context.SubOrderModels
                                                   .Where(o => o.OrderModel == orders[i])
                                                   .ToList();
                }
            }

            return(orders);
        }
Exemplo n.º 14
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.º 15
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.º 16
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.º 17
0
        public List <OrderModels> GetTodaysOrdersByFilter(string phoneNumber, string postalCode, int orderId)
        {
            using (var context = new TakeThaiContext())
            {
                if (orderId > 0)
                {
                    return
                        (context.OrderModels
                         .Include(c => c.CustomerModels)
                         .Include(c => c.CustomerDeliveryAddressModel)
                         .Where(c => c.OrderPlacedDate.Date == DateTime.Today)
                         .Where(o => o.Id == orderId)
                         .OrderBy(c => c.Id)
                         .ToList());
                }

                if (!string.IsNullOrEmpty(postalCode))
                {
                    return
                        (context.OrderModels
                         .Include(c => c.CustomerModels)
                         .Include(c => c.CustomerDeliveryAddressModel)
                         .Where(c => c.OrderPlacedDate.Date == DateTime.Today)
                         .Where(o => o.CustomerDeliveryAddressModel.PostalCode == postalCode)
                         .OrderBy(c => c.Id)
                         .ToList());
                }

                if (!string.IsNullOrEmpty(phoneNumber))
                {
                    return
                        (context.OrderModels
                         .Include(c => c.CustomerModels)
                         .Include(c => c.CustomerDeliveryAddressModel)
                         .Where(c => c.OrderPlacedDate.Date == DateTime.Today)
                         .Where(o => o.CustomerModels.MobileNumber == phoneNumber || o.CustomerModels.TelephoneNumber == phoneNumber)
                         .OrderBy(c => c.Id)
                         .ToList());
                }

                return(null);
            }
        }
Exemplo n.º 18
0
        public List <ProductCategory> GetAllProductCategories()
        {
            var productCategoriesList = new List <ProductCategory>();

            using (var context = new TakeThaiContext())
            {
                productCategoriesList = context.ProductCategories
                                        .Include(p => p.ProductModels)
                                        .ToList();

                foreach (var category in productCategoriesList)
                {
                    foreach (var productModel in category.ProductModels)
                    {
                        productModel.ProductSubModels = context.ProductSubModels.Where(x => x.ProductModel == productModel).ToList();
                    }
                }
            }

            return(productCategoriesList);
        }
Exemplo n.º 19
0
        public List <ProductSubModels> GetAllProductSubProducts(string productName)
        {
            var productSubModels = new List <ProductSubModels>();

            if (string.IsNullOrEmpty(productName))
            {
                return(productSubModels);
            }

            using (var context = new TakeThaiContext())
            {
                var product = context.ProductModels.Where(p => p.Name.ToLower() == productName.ToLower()).FirstOrDefault();

                if (product != null)
                {
                    productSubModels = context.ProductSubModels.Where(po => po.ProductModelId == product.Id).ToList();
                }
            }

            return(productSubModels);
        }
Exemplo n.º 20
0
        public List <ProductSubModels> GetProductSubModels(int productId)
        {
            try
            {
                if (productId <= 0)
                {
                    return(null);
                }

                using (var context = new TakeThaiContext())
                {
                    return(context.ProductSubModels
                           .Where(p => p.ProductModel.Id == productId)
                           .Include(p => p.ProductModel)
                           .ToList());
                }
            } catch
            {
                return(null);
            }
        }
Exemplo n.º 21
0
        public List <SubOrderModels> GetSubOrdersByOrderId(int id)
        {
            List <SubOrderModels> suborderModelList = new List <SubOrderModels>();

            using (var context = new TakeThaiContext())
            {
                var orderModel = context.OrderModels.FirstOrDefault(o => o.Id == id);
                if (orderModel != null)
                {
                    suborderModelList = context.SubOrderModels
                                        .Where(s => s.OrderModel == orderModel)
                                        .Include(s => s.ProductSubModels)
                                        .Include(s => s.ProductSubModels.ProductModel)
                                        .Include(s => s.CustomerProductRequestsModelsList)
                                        .Include(s => s.SubOrderSpecialRequestModel)
                                        .ThenInclude(x => x.SpecialRequestOptionsPreConfiguredModel)
                                        .ToList();
                }
            }

            return(suborderModelList);
        }
Exemplo n.º 22
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.º 23
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);
            }
        }
Exemplo n.º 24
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.º 25
0
        public PdfDocument GenerateEndOfDayDownload(EndOfDayModel endOfDayModel)
        {
            using (var context = new TakeThaiContext())
            {
                var orders = context.OrderModels.Where(x => x.OrderReceivedDate.Date == endOfDayModel.DateRequested.Date).ToList();

                if (endOfDayModel.OrderType.ToLowerInvariant() != "all")
                {
                    if (endOfDayModel.ReportType.ToLowerInvariant() == "delivery")
                    {
                        orders = orders.Where(x => x.DeliveryOrCollection == "Delivery").ToList();
                    }
                    else if (endOfDayModel.ReportType.ToLowerInvariant() == "collection")
                    {
                        orders = orders.Where(x => x.DeliveryOrCollection == "Collection").ToList();
                    }
                    else if (endOfDayModel.ReportType.ToLowerInvariant() == "counter")
                    {
                        orders = orders.Where(x => x.DeliveryOrCollection == "Counter").ToList();
                    }
                }

                if (endOfDayModel.ReportType.ToLowerInvariant() != "all")
                {
                    if (endOfDayModel.ReportType.ToLowerInvariant() == "card")
                    {
                        orders = orders.Where(x => x.PaymentMethod.ToLowerInvariant() == "Card").ToList();
                    }
                    else if (endOfDayModel.ReportType.ToLowerInvariant() == "cash")
                    {
                        orders = orders.Where(x => x.PaymentMethod.ToLowerInvariant() == "Cash").ToList();
                    }
                }

                using (var stream = new MemoryStream())
                {
                    var myHtml = $"<div style='text-align: center; display: block;'> <img src='https://www.takethai.co.uk/wp-content/uploads/Take-Thai-Logo.png'  /></div> <br /> " +
                                 "<hr /> <br /><p></p><div style='text-align: right'>";

                    if (endOfDayModel.ReportType.ToLowerInvariant() != "all")
                    {
                        myHtml = $"{myHtml} <p>This report is from all {endOfDayModel.ReportType} payments.</p>";
                    }
                    else
                    {
                        myHtml = $"{myHtml} <p>This report is from all payments.</p>";
                    }

                    if (endOfDayModel.OrderType.ToLowerInvariant() == "all")
                    {
                        myHtml = $"{myHtml} <p>Total for all orders on {endOfDayModel.DateRequested.Date:dd'/'MM'/'yyyy}: <strong>£{orders.Sum(x => x.TotalCost)}</strong> </p>";
                    }
                    else
                    {
                        myHtml = $"{myHtml} <p>Total for {endOfDayModel.OrderType} on {endOfDayModel.DateRequested.Date:dd'/'MM'/'yyyy}: <strong>£{orders.Sum(x => x.TotalCost)}</strong> </p>";
                    }

                    myHtml = $"{myHtml} </div>";

                    var htmlToPdf = new HtmlToPdf();
                    var pdf       = htmlToPdf.RenderHtmlAsPdf(myHtml);

                    return(pdf);
                }
            }
        }