Ejemplo n.º 1
0
        public IActionResult CreateTopping(CreateToppingViewModel newItem)
        {
            var newCreatedItem = new Topping
            {
                Active      = newItem.Active == "true" ? true : false,
                ToppingName = newItem.Name,
                CreateBy    = 1,
                CreateTime  = DateTime.UtcNow,
                UpdateBy    = 1,
                UpdateTime  = DateTime.UtcNow
            };

            _ctx.Topping.Add(newCreatedItem);
            _ctx.SaveChanges();

            foreach (var toppingTypeId in newItem.ToppingTypeIds)
            {
                var toppingSysRef = new ToppingSystemReference
                {
                    ToppingId     = newCreatedItem.Id,
                    ToppingTypeId = toppingTypeId,
                    CreateBy      = 1,
                    CreateTime    = DateTime.UtcNow,
                    UpdateBy      = 1,
                    UpdateTime    = DateTime.UtcNow
                };
                _ctx.ToppingSystemReference.Add(toppingSysRef);
            }
            _ctx.SaveChanges();
            var success = newItem.Name.ToString();

            ViewBag.Create = success;
            return(Redirect("CreateTopping"));
        }
Ejemplo n.º 2
0
        public IActionResult Checkout(string note)
        {
            var cart    = SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart");
            var orderId = SessionHelper.GetObjectFromJson <long>(HttpContext.Session, "orderId");
            var order   = _ctx.Order.FirstOrDefault(x => x.Id == orderId);
            var ordersForCustomerToday = _ctx.Order.Where(x => x.CustomerEmail == order.CustomerEmail &&
                                                          x.CreateTime.ToLocalTime().Day == DateTime.Today.Day &&
                                                          x.OrderStatusId != 2 &&
                                                          x.CommunityId != 1);

            if (ordersForCustomerToday.Count() > 1)
            {
                TempData["ErrorMessage"] = "Orders are limited to only one per day, cancel your last order if you must create a new one.";
                return(RedirectToAction("ShortendOrderView", "Home"));
            }

            ViewBag.cart = cart;

            order.Note = note;
            _ctx.SaveChanges();


            foreach (var item in cart)
            {
                var orderItem = new OrderItem
                {
                    MenuItemId = item.MenuItem.Id,
                    Quantity   = item.Quantity,
                    SizeId     = item.SizeId,
                    CreateBy   = 1,
                    UpdateBy   = 1,
                    CreateTime = DateTime.UtcNow,
                    UpdateTime = DateTime.UtcNow,
                    OrderId    = orderId
                };
                _ctx.OrderItem.Add(orderItem);
                _ctx.SaveChanges();

                foreach (var topping in item.Toppings)
                {
                    var toppingItem = new OrderItemTopping
                    {
                        OrderItemId = orderItem.Id,
                        ToppingId   = topping.Id,
                        CreateBy    = 1,
                        UpdateBy    = 1,
                        CreateTime  = DateTime.UtcNow,
                        UpdateTime  = DateTime.UtcNow
                    };
                    _ctx.OrderItemTopping.Add(toppingItem);
                }

                var orderToUpdate = _ctx.Order.First(x => x.Id == orderId);
                orderToUpdate.OrderStatusId = _ctx.OrderStatus.SingleOrDefault(x => x.Status == "Pending").Id;

                _ctx.SaveChanges();
            }
            return(RedirectToAction("OrderInfoForCustomer", "Orders"));
        }
Ejemplo n.º 3
0
 public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
 {
     user.CreateTime = DateTime.UtcNow;
     user.UpdateTime = DateTime.UtcNow;
     _ctx.User.Add(user);
     _ctx.SaveChanges();
     return(IdentityResult.Success);
 }
Ejemplo n.º 4
0
        public IActionResult ShortendOrderView(CartViewModel cartViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("ShortendOrderView", "Home"));
            }

            //TODO REACTIVATE FOR PRODUCTION
            //if (!cartViewModel.IsEmployee)
            //{
            //    TimeSpan now = DateTime.Now.TimeOfDay;
            //    TimeSpan start = new TimeSpan(06, 0, 0);
            //    TimeSpan end = new TimeSpan(10, 0, 0);
            //    if (now < start || now > end)
            //    {
            //        TempData["ErrorMessage"] = "Delivery orders must be placed between 6 am and 10 am!";
            //        return RedirectToAction("ShortendOrderView", "Home");
            //    }
            //}

            var cart = SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart");

            ViewBag.cart = cart;

            var person = _ctx.Person.FirstOrDefault(x => x.Email == cartViewModel.Email);

            if (person == null)
            {
                person = new Person
                {
                    Active     = true,
                    FirstName  = cartViewModel.FirstName,
                    LastName   = cartViewModel.LastName,
                    SendEmail  = cartViewModel.EmailConsent,
                    Email      = cartViewModel.Email,
                    CreateBy   = 1,
                    UpdateBy   = 1,
                    UpdateTime = DateTime.UtcNow,
                    CreateTime = DateTime.UtcNow
                };
                _ctx.Person.Add(person);
                _ctx.SaveChanges();
            }
            else
            {
                person.SendEmail = cartViewModel.EmailConsent;
                _ctx.Person.Update(person);
                _ctx.SaveChanges();
            }

            var order = new Order
            {
                OrderStatusId     = _ctx.OrderStatus.SingleOrDefault(x => x.Status == "InProgress").Id,
                CustomerEmail     = cartViewModel.Email,
                CustomerFirstName = cartViewModel.FirstName,
                CustomerLastName  = cartViewModel.LastName,
                Note         = cartViewModel.Note,
                CommunityId  = cartViewModel.CommunityId > 0 ? cartViewModel.CommunityId : 1,
                AddressLine1 = cartViewModel.AddressLine1,
                AddressLine2 = cartViewModel.AddressLine2,
                City         = cartViewModel.City,
                ZipCode      = cartViewModel.Zipcode,
                CreateBy     = 1,
                UpdateBy     = 1,
                CreateTime   = DateTime.UtcNow,
                UpdateTime   = DateTime.UtcNow
            };

            _ctx.Order.Add(order);
            _ctx.SaveChanges();

            if (SessionHelper.GetObjectFromJson <long>(HttpContext.Session, "orderId") == 0)
            {
                SessionHelper.SetObjectAsJson(HttpContext.Session, "orderId", order.Id);
            }

            SessionHelper.SetObjectAsJson(HttpContext.Session, "isEmployee", cartViewModel.IsEmployee);


            return(RedirectToAction("OrderMenu", "Cart"));
        }