Esempio n. 1
0
        public IActionResult Register(UserForRegister userForRegister)
        {
            var userExists = _authService.UserExists(userForRegister.Email);

            if (!userExists.Success)
            {
                return(BadRequest(userExists.Message));
            }
            var registerResult = _authService.Register(userForRegister, userForRegister.Password);

            _basketService.Add(new Basket {
                UserId = registerResult.Data.Id
            });
            _favoriteService.Add(new Favorite {
                UserId = registerResult.Data.Id
            });

            var result = _authService.CreateAccessToken(registerResult.Data);

            if (result.Success)
            {
                return(Ok(result.Data));
            }
            return(BadRequest(result.Message));
        }
        public void AddBasket_ThenABasketIsreturned()
        {
            ConfigureBasketServiceAdd();
            var basket = _basketService.Add(It.IsAny <Basket>());

            Assert.IsNotNull(basket);
        }
Esempio n. 3
0
        public IActionResult Add(Basket basket)
        {
            var result = _basketService.Add(basket);

            if (result.Success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public IActionResult Add(Basket basket)
        {
            var result = _basketSerivce.Add(basket);

            if (result.Success == true)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Esempio n. 5
0
        public ActionResult AddToBasket(ProductViewModel viewModel)
        {
            basketService.Add(new ProductInBasket
            {
                ProductId = viewModel.ProductId,
                UserId    = "user1",
                Count     = 1
            });

            return(Redirect("Index"));
        }
Esempio n. 6
0
        public IActionResult ValidateBasket(Guid basketId)
        {
            User   user   = _userService.Me(_httpContextAccessor.HttpContext.User);
            Basket basket = _service.Get(b => b.Id == basketId && b.State == BasketState.NotValidated).SingleOrDefault();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (basket == null)
            {
                return(BadRequest("Basket not found"));
            }
            else if (basket.Owner.Id != user.Id && user.Role < Role.Admin)
            {
                return(StatusCode(403, "Not your basket and not an Admin."));
            }

            Transaction transaction = new Transaction()
            {
                Order   = basket,
                OrderId = basketId,
                Owner   = user,
                OwnerId = user.Id,
                State   = TransactionState.Payed
            };

            foreach (BasketItem bi in basket.BasketItems)
            {
                _stockMovementService.Add(new StockMovement()
                {
                    Amount        = -bi.Quantity,
                    LastInventory = _inventoryService.Get(i => i.Item.Id == bi.ItemId).MaxBy(i => i.Timestamp).SingleOrDefault(),

                    Item      = bi.Item,
                    Timestamp = DateTime.Now,
                    Type      = StockMovementType.Reserved
                });
            }

            basket.Transaction = transaction;
            basket.State       = BasketState.Payed;

            _transactionService.Add(transaction);
            _service.Put(basket);
            _service.Add(new Basket()
            {
                State = BasketState.NotValidated,
                Owner = user
            });

            return(Ok(_service.Mine(HttpContext.User)));
        }
Esempio n. 7
0
        public IActionResult Add(int productId, int?quantity, string tags)
        {
            var basket = new Basket {
                ProductId = productId, Quantity = quantity ?? 1, Description = tags
            };

            _basketService.Add(basket);
            return(Json(new AjaxResult {
                Status = AjaxStatus.Normal, Data = new BasketData(_basketService.Get())
            }));
        }
Esempio n. 8
0
        public ActionResult <BasketViewModel> Add(Guid basketId, Guid itemId)
        {
            var basket = _basketService.Add(basketId, itemId);

            if (basket == null)
            {
                return(NotFound());
            }

            return(basket);
        }
Esempio n. 9
0
        public IActionResult Add(Basket basket)
        {
            basket.CreateDate = DateTime.Now;
            var result = _basketService.Add(basket);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public async Task <IActionResult> Add(Basket basket)
        {
            var result = await _basketService.Add(basket);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Esempio n. 11
0
        public async Task AddToBasket(ProductModel product)
        {
            if (!await IsAuth())
            {
                await _js.InvokeVoidAsync(
                    "alert",
                    "Пожалуйста авторизутесь в системе для добавления товаров в корзину. Кнопка для входа в верхнем правом углу."
                    );

                return;
            }
            await _basket.Add(product);
        }
        public IActionResult Add(int id)
        {
            if (!(Convert.ToBoolean(HttpContext.Session.GetString("Active"))))
            {
                return(RedirectToAction("Login", "IO"));
            }
            //_productService.GetById
            //if (true)
            //{
            //}
            string tempId         = HttpContext.Session.GetString("id");
            int    userId         = int.Parse(tempId);
            var    basketProducts = _basketService.Baskets(userId);
            Basket basket         = new Basket();

            if (basketProducts.Count == 0)
            {
                basket.ProductId = id;
                basket.UserID    = userId;
                _basketService.Add(basket);

                return(RedirectToAction("Listele", "Basket"));
            }



            foreach (var item in basketProducts)
            {
                if (item.ProductId == id) // 2 tane aynı ürün eklenmesi izin verilmez siparişlere.
                {
                    return(RedirectToAction("Listele", "Basket"));
                }
            }
            basket.ProductId = id;
            basket.UserID    = userId;
            _basketService.Add(basket);

            return(RedirectToAction("Listele", "Basket"));
        }
        private IDataResult <Basket> CreateNewBasketIfNotHaveActive()
        {
            int userId = GetUserIdFromToken();
            var result = _basketService.GetByUserIdActive(userId).Data;

            if (result != null)
            {
                return(new SuccessDataResult <Basket>(result));
            }

            Basket basket = new Basket
            {
                UserId = GetUserIdFromToken()
            };

            _basketService.Add(basket);
            return(new SuccessDataResult <Basket>(basket, BusinessMessages.BasketAdded));
        }
Esempio n. 14
0
        public async Task <IActionResult> BasketAdd(int id)
        {
            var product = await _productService.GetById(id);

            var usrid = await _userService.UserIdFromName(User.Identity.Name);

            if (product != null)
            {
                var basketcontrol = await _basketService.GetByUserProductId(usrid, id);

                if (basketcontrol != null)
                {
                    basketcontrol.BasketQuantity += 1;
                    await _basketService.Edit(basketcontrol);
                }
                else
                {
                    await _basketService.Add(new BasketDTO { AppUserId = usrid, AppUsers = null, BasketQuantity = 1, ProductId = product.Id, Products = null, Status = Status.Active });
                }
            }
            return(RedirectToAction("Products", "Product"));
        }
Esempio n. 15
0
 public Task Add(ProductModel product) => _service.Add(product);
 public IActionResult Post([FromBody] Basket value)
 {
     _basketService.Add(value);
     return(Created("", "Basket Created !"));
 }