Exemplo n.º 1
0
        /// <summary>
        /// Ensures that upon getting to the register page, the correct fields are attached and then saved to the database to be later called on to login.
        /// </summary>
        /// <returns>A new user that gets posted to the db </returns>
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            RegisterDTO registerDTO = new RegisterDTO()
            {
                Username    = Input.Username,
                Password    = Input.Password,
                Email       = Input.Email,
                Phonenumber = Input.Phonenumber,
                Roles       = new List <string>()
                {
                    "guest"
                }
            };

            var newUsers = await UserService.Register(registerDTO);

            CreateCart cart = new CreateCart
            {
                UserId = newUsers.Id
            };
            CookieOptions cookieoption = new CookieOptions();

            cookieoption.Expires = new DateTimeOffset(DateTime.Now.AddDays(7));
            HttpContext.Response.Cookies.Append("UserId", newUsers.Id, cookieoption);

            await CartService.Create(cart);

            return(RedirectToPage("/Categories/Index"));
        }
Exemplo n.º 2
0
        private ShoppingCartDto CreateCart(Guid id)
        {
            var command = new CreateCart(
                cartId: id);

            ServiceLocator.Bus.Send(command);
            return(new ShoppingCartDto
            {
                Id = id,
                Items = new ShoppingCartItemDto[0]
            });
        }
Exemplo n.º 3
0
        public async Task <CreateCart> Create(CreateCart cart)
        {
            CreateCart newCart = new CreateCart()
            {
                UserId = cart.UserId
            };

            _context.Entry(newCart).State = EntityState.Added;
            await _context.SaveChangesAsync();

            return(newCart);
        }
 public ShoppingCartApiController(
     LoadCart loadCart,
     CreateCart createCart,
     LoadProductBaseData loadProductBaseData,
     LoadRetailOfferData loadRetailOfferData,
     IHttpContextAccessor httpContextAccessor)
 {
     this.loadCart            = loadCart;
     this.createCart          = createCart;
     this.loadProductBaseData = loadProductBaseData;
     this.loadRetailOfferData = loadRetailOfferData;
     this.httpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 5
0
        public async Task <CartResponse> CreateCart(CreateCartRequest request)
        {
            var command = new CreateCart
            {
                AggregateRootId = Guid.NewGuid(),
                CustomerId      = request.CustomerId
            };

            await dispatcher.SendAndPublishAsync <CreateCart, Cart>(command);

            var model = await GetCartReadModel(command.AggregateRootId);

            return(model.ToCartResponse());
        }
        public async Task <IActionResult> Post()
        {
            try
            {
                var createCart = new CreateCart(Guid.NewGuid(), DateTime.Now);
                await _mediator.Send(createCart);

                return(Ok(new { message = "New cart created" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This was one trickier, but on post we attach the user id to the cart. So when a new user is created, so is a cart and by doing so when a user clicks on add to cart, it attaches to the specific ids.
        /// </summary>
        /// <returns>Item in cart </returns>
        public async Task OnPostAsync()
        {
            var UserId = HttpContext.Request.Cookies["userId"];

            CreateCart cart = await cartService.GetOne(UserId);

            CartItem cartItem = new CartItem()
            {
                MealId       = Product.Id,
                Price        = Product.Price,
                Quantity     = cart.Quantity,
                CreateCartId = cart.Id
            };

            CartItem record = await cartService.AddItemToCart(cartItem.MealId, cartItem.Price, cartItem.Quantity, cartItem.CreateCartId);
        }
Exemplo n.º 8
0
 public static Result <Cart, ErrorType> GetCart(LoadCart loadCart, CreateCart createCart, int userId) =>
 loadCart(userId)
 .Match(
     onSome: cart => cart,
     onNone: () => createCart(userId));
Exemplo n.º 9
0
        public async Task <ActionResult <CreateCart> > GetCart(string userId)
        {
            CreateCart Cart = await _cart.GetOne(userId);

            return(Cart);
        }
Exemplo n.º 10
0
        public async Task <ActionResult <CreateCart> > Create(CreateCart cart)
        {
            await _cart.Create(cart);

            return(CreatedAtAction("GetCartItems", new { id = cart.Id }, cart));
        }
Exemplo n.º 11
0
 public Task <CreateCart> UpdateQuantity(CreateCart cart)
 {
     throw new NotImplementedException();
 }