Beispiel #1
0
        public async Task <bool> OrderAsync(CartViewModel model, ApplicationUser user)
        {
            var order    = new Bestallning();
            var customer = await _dbService.GetCustomerAsync(user.Id);

            order.Kund             = customer;
            order.BestallningDatum = DateTime.Now;
            order.KundId           = customer.KundId;
            order.Levererad        = false;

            if (model.BonusPoints >= 100)
            {
                if (model.Dishes.Any(e => e.DishId == 1104))
                {
                    model.Dishes.Find(e => e.DishId == 1104).Quantity++;
                }
                else
                {
                    var dish = await GetDishAsync(1104);

                    dish.Quantity++;
                    model.Dishes.Add(dish);
                }

                model.BonusPoints -= 100;
            }

            foreach (var dish in model.Dishes)
            {
                var matratt = await _dbService.GetMatrattAsync(dish.DishId);

                var orderDetail = new BestallningMatratt()
                {
                    Antal       = dish.Quantity,
                    Bestallning = order,
                    Matratt     = matratt,
                    MatrattId   = matratt.MatrattId
                };

                order.BestallningMatratt.Add(orderDetail);
            }

            order.Totalbelopp = user.IsPremium ? model.PremiumPrice : model.TotalPrice;

            var result = await _dbService.AddNewOrderAsync(order);

            if (result)
            {
                user.BonusPoints = model.BonusPoints;
            }
            return(await Task.FromResult <bool>(true));
        }
Beispiel #2
0
        public async Task <IActionResult> Manage()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var model    = new ManageViewModel();
            var customer = await _dbService.GetCustomerAsync(currentUser.Id);

            if (customer == null)
            {
                model.Email      = currentUser.Email;
                model.IdentityId = currentUser.Id;
            }
            else
            {
                model = _userRepository.UpdateModel(customer, model);
            }

            return(View(model));
        }