Exemple #1
0
        public async Task <IActionResult> CreateAuth(CartModel cart, string OrderNotes)
        {
            DoneModelView done = new DoneModelView();

            if (ModelState.IsValid)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index"));
                }

                UserModel user  = _userService.GetCurrentUser(HttpContext);
                var       order = await _orderService.Create(cart, user, OrderNotes);

                var products = await _productService.GetProductsByIdList(order.Cart.ItemList.Select(id => id.ProductId).ToList());

                done.order    = order;
                done.products = products;
            }

            var categories = await _categoryService.GetAll();

            ViewData["Categories"] = categories;
            var contact = _contactService.Get();

            ViewData["contact"] = contact;
            return(View("Done", done));
        }
Exemple #2
0
        public async Task <IActionResult> Create(CartModel cart, OrderUserViewModel model, string OrderNotes)
        {
            DoneModelView done = new DoneModelView();

            if (ModelState.IsValid)
            {
                var validate = _userService.Validate("Email", model.Email);
                if (validate.Success)
                {
                    ModelState.AddModelError("", "Email \"" + model.Email + "\" is already taken");
                }
                UserModel user = new UserModel();
                user.Email    = model.Email;
                user.LastName = model.LastName;
                user.Name     = model.Name;
                user.Phone    = model.Phone;
                user.Address  = model.Address;
                user.Created  = DateTime.Now;
                if (model.CreateAccount == true)
                {
                    if (string.IsNullOrWhiteSpace(model.Password))
                    {
                        ModelState.AddModelError("", "Password is required");
                    }
                    if (model.Password != model.ConfirmPassword)
                    {
                        ModelState.AddModelError("", "Enter the right password");
                    }

                    _userService.SignUp(user, "email", user.Email, model.Password);
                    _userService.AddToRole(user, "user");
                }

                var order = await _orderService.Create(cart, user, OrderNotes);

                var products = await _productService.GetProductsByIdList(order.Cart.ItemList.Select(id => id.ProductId).ToList());

                done.order    = order;
                done.products = products;
            }

            var categories = await _categoryService.GetAll();

            ViewData["Categories"] = categories;
            var contact = _contactService.Get();

            ViewData["contact"] = contact;
            return(View("Done", done));
        }