Exemple #1
0
 /// <summary>
 /// Cart controller
 /// </summary>
 /// <param name="bll"></param>
 public CartsViewController(IAppBLL bll)
 {
     _bll              = bll;
     _cartMapper       = new CartMapper();
     _itemInCartMapper = new ItemInCartMapper();
     _itemMapper       = new ItemMapper();
 }
Exemple #2
0
 public ItemsController()
 {
     _itemConfig  = new Configuration.Configurations();
     _itemService = _itemConfig.GetItemService();
     _itemMapper  = new ItemMapper(_itemConfig);
     _cartMapper  = new CartMapper();
 }
 public CartController(IUserContext userContext, IDataReader dataReader, IDataWriter dataWriter, CartMapper mapper)
 {
     _userContext = userContext;
     _dataReader  = dataReader;
     _dataWriter  = dataWriter;
     _mapper      = mapper;
 }
Exemple #4
0
        public async Task <IActionResult> Register([FromForm] Register register,
                                                   [FromServices] CartMapper mapper)
        {
            if (!ModelState.IsValid)
            {
                return(CreatedAtAction("Register", register));
            }

            User user = await _context.Users.FirstOrDefaultAsync(u => u.Email == register.Email);

            if (user == null)
            {
                var userEntry = await _context.Users.AddAsync(new User
                {
                    Email        = register.Email,
                    PasswordHash = register.Password
                });

                await Authenticate(GenerateUserClaims(userEntry.Entity));

                await mapper.MapTo(userEntry.Entity);

                return(RedirectToAction("Index", "Home"));
            }
            ModelState.AddModelError("", "User already exists.");
            return(CreatedAtAction("Register", register));
        }
        public async Task <ResultInfo> Create([FromBody] CartRequestModel request)
        {
            if (!ModelState.IsValid)
            {
                var modelErrors = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        modelErrors.Add(modelError.ErrorMessage);
                    }
                }

                return(new ResultInfo(String.Join(' ', modelErrors), "403"));
            }

            var model = await _cartService.GetByProductUid(request.ProductUid);

            if (model == null)
            {
                model = new CartModel();

                CartMapper.Map(request, model);

                await _cartService.Create(model, null);
            }
            else
            {
                model.ProductCount += request.Count;

                await _cartService.Update(model, null);
            }

            return(new ResultInfo());
        }
Exemple #6
0
 public CartController(
     IMediator mediator,
     CartMapper mapper,
     SessionCartHandler sessionCartHandler)
 {
     _mediator           = mediator;
     _mapper             = mapper;
     _sessionCartHandler = sessionCartHandler;
 }
Exemple #7
0
        public async Task <IActionResult> Login([FromForm] Login login,
                                                [FromServices] CartMapper mapper)
        {
            if (!ModelState.IsValid)
            {
                return(CreatedAtAction("Login", login));
            }

            User user = await _context.Users.FirstOrDefaultAsync(u => u.Email == login.Email);

            if (user != null)
            {
                await Authenticate(GenerateUserClaims(user));

                await mapper.MapTo(user);

                return(RedirectToAction("Index", "Home"));
            }
            ModelState.AddModelError("", "Incorrect login or password.");
            return(CreatedAtAction("Login", login));
        }
Exemple #8
0
 /// <summary>
 /// Carts controller for admin
 /// </summary>
 /// <param name="bll"></param>
 public CartsController(IAppBLL bll)
 {
     _bll        = bll;
     _cartMapper = new CartMapper();
 }
Exemple #9
0
 public CartController()
 {
     _itemConfig  = new Configuration.Configurations();
     _userService = _itemConfig.GetUserService();
     _cartMapper  = new CartMapper();
 }
 public CartCrudFactory()
 {
     mapper = new CartMapper();
     dao    = SqlDao.GetInstance();
 }
 public JsonResult Get()
 {
     return(Json(CartMapper.Map(cartsClient.GetCart().Result), JsonRequestBehavior.AllowGet));
 }