Beispiel #1
0
        public virtual async Task <ActionResult> CreateFactor(CreateFactorViewModel factorViewModel)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(View());
            }
            else
            {
                if (string.IsNullOrEmpty(user.FirstName) && string.IsNullOrEmpty(user.LastName) && string.IsNullOrEmpty(user.Mobile) && string.IsNullOrEmpty(user.Address))
                {
                    user.FirstName = factorViewModel.Name;
                    user.LastName  = factorViewModel.LastName;
                    user.Mobile    = factorViewModel.PhoneNumber;
                    user.Address   = factorViewModel.Address;
                }

                await _shoppingCartService.CreateFactor(factorViewModel);

                await _unitOfWork.SaveAllChangesAsync();

                return(Content(Url.Action("UserFactor", "Home", new { area = "ShoppingCart" })));
            }
        }
        public async Task CreateFactor(CreateFactorViewModel factorViewModel)
        {
            var factor = new Factor
            {
                Name        = factorViewModel.Name,
                Address     = factorViewModel.Address,
                UserId      = Convert.ToInt32(HttpContext.Current.User.Identity.GetUserId()),
                PhoneNumber = factorViewModel.PhoneNumber,
                LastName    = factorViewModel.LastName,
                IssueDate   = DateTime.Now
            };


            var factorProducts = new List <FactorProduct>();

            foreach (var factorProduct in factorViewModel.Products)
            {
                var selectedProduct = await _unitOfWork.Set <Product>().FindAsync(factorProduct.ProductId);

                factorProducts.Add(new FactorProduct
                {
                    Count     = factorProduct.Count,
                    Price     = selectedProduct.Prices.OrderByDescending(x => x.Date).FirstOrDefault().Price,
                    Discount  = selectedProduct.Discounts.OrderByDescending(x => x.StartDate).FirstOrDefault().Discount,
                    ProductId = selectedProduct.Id
                });
            }

            factor.Products = factorProducts;
            _factors.Add(factor);
        }
Beispiel #3
0
        public virtual async Task <ActionResult> CreateFactor(CreateFactorViewModel factorViewModel)
        {
            await _shoppingCartService.CreateFactor(factorViewModel);

            await _unitOfWork.SaveAllChangesAsync();

            return(Content(Url.Action("UserFactor", "Home", new { area = "ShoppingCart" })));
        }