public void SetOrderConfirmed(string userId)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                OrderHeader order = db.OrderHeaders.Find(Order.OrderNumber);

                if (order == null)
                {
                    return;
                }

                order.OrderStatus     = "Confirmed";
                order.OrderDatePlaced = DateTime.Now;
                order.PaymentReceived = true;
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                ReleaseAllStock(order.OrderNumber);

                OrderHeader.UpdatePopularItems(order.OrderNumber);

                Initialize(userId);
            }
        }
        public void SetModel(string customerNumber, OrderHeader order, decimal courierFee, decimal postalFee)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                OrderStatus = order.OrderStatus;

                SetDeliveryOptions(order, courierFee, postalFee);

                List <CustomerAddress> addresses = db.CustomerAddresses
                                                   .Where(c => c.CustomerNumber == customerNumber)
                                                   .ToList();

                CustomerAddress address = addresses
                                          .Where(c => c.ToString() == order.DeliveryAddress)
                                          .FirstOrDefault();

                int    selectedAddressNumber = 0;
                string addressName           = "";

                if (address == null)
                {
                    selectedAddressNumber = 0;
                    addressName           = "Current";
                }
                else
                {
                    selectedAddressNumber = address.AddressNumber;
                    addressName           = address.AddressName;
                }

                SetAddressNameOptions(customerNumber, selectedAddressNumber);

                if (address == null)
                {
                    AddressNameOptions.Add(new SelectListItem {
                        Text = "Current", Value = "0", Selected = true
                    });
                    Address = new CustomerAddress
                    {
                        AddressCity       = order.DeliveryAddressCity,
                        AddressLine1      = order.DeliveryAddressLine1,
                        AddressLine2      = order.DeliveryAddressLine2,
                        AddressLine3      = order.DeliveryAddressLine3,
                        AddressLine4      = order.DeliveryAddressLine3,
                        AddressName       = "Current",
                        AddressNumber     = 0,
                        AddressPostalCode = order.DeliveryAddressPostalCode,
                        AddressSuburb     = order.DeliveryAddressSuburb,
                        CustomerNumber    = customerNumber
                    };
                }
                else
                {
                    Address = address;
                }

                if (order.DeliveryDate == null)
                {
                    prefDeliveryDateTime = OrderHeader.GetSpecialSuggestedDeliveryTime();
                }
                else
                {
                    if (order.DeliveryDate < OrderHeader.GetSpecialSuggestedDeliveryTime())
                    {
                        prefDeliveryDateTime = OrderHeader.GetSpecialSuggestedDeliveryTime();
                    }
                    else
                    {
                        prefDeliveryDateTime = order.DeliveryDate;
                    }
                }

                AddressName = AddressNameOptions
                              .Where(c => c.Selected == true)
                              .Select(c => c.Text)
                              .FirstOrDefault();

                SelectedAddress = selectedAddressNumber;

                DaysToAddToMinDate = OrderHeader.GetDaysToMinDate();

                SetTextBlocks();
            }
        }
 public SaveCartViewModel(string customerNumber, OrderHeader order, decimal courierFee, decimal postalFee)
 {
     SetModel(customerNumber, order, courierFee, postalFee);
 }
Exemple #4
0
        public static OrderHeaderViewModel GetOrder(int orderNumber, string userId)
        {
            OrderHeaderViewModel model = new OrderHeaderViewModel();

            if (orderNumber == 0 || string.IsNullOrEmpty(userId))
            {
                return(model);
            }

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                OrderHeader order = db.OrderHeaders.Find(orderNumber);

                if (order == null)
                {
                    return(model);
                }

                if (order.CustomerNumber != userId)
                {
                    return(model);
                }

                model.ItemsInOrder = db.GetOrderDetails(orderNumber).Select(c => new OrderDetail
                {
                    ItemNumber         = c.ItemNumber,
                    ProductDescription = c.Description,
                    Price          = c.Price,
                    Quantity       = c.Quantity,
                    SupplierName   = c.SupplierName,
                    ProductWeight  = c.Weight ?? 0,
                    OrderItemValue = c.OrderItemValue,
                    SizeType       = c.SizeType
                }).ToList();

                model.Order   = order;
                model.Courier = db.Couriers.Find(order.CourierNumber);
                model.Support = db.Supports.FirstOrDefault();

                // Find the customer's details
                var UserManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var user        = UserManager.FindById(userId);

                model.Order.CustomerName  = user.Name;
                model.Order.CustomerEmail = user.Email;
                model.Order.CustomerPrimaryContactPhone          = user.PhoneNumber;
                model.Order.CustomerPreferredCommunicationMethod = user.PreferredCommunicationMethod;
                model.Order.VATPercentage = db.VATPercentages.FirstOrDefault().VATPercentage1;

                model.NumberOfItemsInOrder = db.GetNumberOfItemsInOrder(model.Order.OrderNumber)
                                             .FirstOrDefault() ?? 0;

                model.MinDispatchDate = OrderHeader.GetDispatchDay(OrderHeader.GetSpecialSuggestedDeliveryTime());

                // Get Payment information

                string orderNumberString = model.Order.OrderNumber.ToString();
                model.PaymentMessages = new List <GetPaymentGatewayMessages_Result>();
                model.PaymentMessages = db.GetPaymentGatewayMessages(orderNumberString).ToList();
            }

            return(model);
        }