public async Task <IActionResult> RemoveFromShoppingCart([FromRoute] int merchandiseId, [FromQuery] int amount) { Merchandise selectedMerchandise = _merchandiseRepository.Merchandises.FirstOrDefault(p => p.MerchandiseId == merchandiseId); if (selectedMerchandise != null) { await _shoppingCart.RemoveFromCart(selectedMerchandise, amount); } else { return(NotFound()); } ShoppingCartItem[] items = await _shoppingCart.GetShoppingCartItems(); _shoppingCart.ShoppingCartItems = items; ShoppingCartResponse shoppingCartResponse = new ShoppingCartResponse { ShoppingCart = _shoppingCart, ShoppingCartTotal = await _shoppingCart.GetShoppingCartTotal() }; return(Ok(new BaseResponse <ShoppingCartResponse> { Data = shoppingCartResponse, Success = true })); }
internal void SendResponse(ShoppingCartResponse response) { this.SendResponse(response, () => { this.Dialog.SendResponse(response); }); }
internal Task SendResponseAsync(ShoppingCartResponse response, CancellationToken cancellationToken = default) { return(this.SendResponseAsync(response, () => { return this.Dialog.SendResponseAsync(response, cancellationToken); })); }
public IActionResult Add(ShoppingCartProductDTO shoppingCartProduct) { //todo : login servise checktoken ı cagır //eğer ilgili token gecersizse login api hata doner bizde sepete ekleme işlemini iptal ederiz., //checktoken başarılı dondugu varsayıp devam ediyoruz. (****eklenecek) //checktoken userın idsini donsun ShoppingCartResponse response = new ShoppingCartResponse(); response = _service.Add(shoppingCartProduct.Token, shoppingCartProduct.UserID, shoppingCartProduct.ProductID, shoppingCartProduct.ProductCount); return(response.Code != (int)Constants.ResponseCode.SUCCESS ? StatusCode(500, response) : StatusCode(201, response)); }
public IShoppingCartFinishedProcessState StartProcess(ShoppingCartCriteria criteria) { ShoppingCartRequest request = this.CreateRequest(criteria); ShoppingCartResponse response = this.SendRequest(request, () => { return(this.Dialog.SendRequest(request)); }); return(new ShoppingCartFinishedProcessState(request, response)); }
public async Task <IShoppingCartFinishedProcessState> StartProcessAsync(ShoppingCartCriteria criteria, CancellationToken cancellationToken = default) { ShoppingCartRequest request = this.CreateRequest(criteria); ShoppingCartResponse response = await this.SendRequestAsync(request, () => { return(this.Dialog.SendRequestAsync(request, cancellationToken)); }).ConfigureAwait(continueOnCapturedContext: false); return(new ShoppingCartFinishedProcessState(request, response)); }
protected IHttpActionResult ShoppingCart(ShoppingCart cart, string error = null) { var response = new ShoppingCartResponse(cart, Url, error); AddLink(new HttpMethod("PATCH"), "add-items", response.Resource, "add-items", null); if (cart.Lines.Any()) AddLink(HttpMethod.Post, "checkout", response.Resource, "CO", null); if (response.Error != null) LogResponseError(response.Error); return Ok(response); }
public IActionResult UpdateProductCountOfShoppingCart(List <UpdateProductCountDTO> parameters) { ShoppingCartResponse response = new ShoppingCartResponse(); foreach (UpdateProductCountDTO item in parameters) { response = _service.UpdateProductCountOfShoppingCart(item.Token, item.ProductID, item.NewCount); if (response.Code != 0) { return(StatusCode(500, response)); } } return(response.Code != (int)Constants.ResponseCode.SUCCESS ? StatusCode(500, response) : StatusCode(200, response)); }
public async Task <ShoppingCartResponse> GetCurrentCartFor([FromHeader] string Authorization, [FromQuery] string deviceId, [FromQuery] string userId) { var cart = await Repository.GetCurrentCartForUser(deviceId, null); var response = new ShoppingCartResponse(); if (cart != null) { var data = new ShoppingCartResponse.CartData(); data.Id = cart.ShoppingCartId.ToString(); data.Products = cart.Products ?? new List <Product>(); response.DataResponse = data; } return(response); }
public async Task <IActionResult> GetAll() { ShoppingCartItem[] items = await _shoppingCart.GetShoppingCartItems(); _shoppingCart.ShoppingCartItems = items; ShoppingCartResponse shoppingCartResponse = new ShoppingCartResponse { ShoppingCart = _shoppingCart, ShoppingCartTotal = await _shoppingCart.GetShoppingCartTotal() }; return(Ok(new BaseResponse <ShoppingCartResponse> { Data = shoppingCartResponse, Success = true })); }
public ShoppingCartResponse GetShoppingCartofUser(string token) { ShoppingCartResponse response = new ShoppingCartResponse(); try { ShoppingCart shoppingCart = _repositoryShoppingCart.Get(t => t.Token == token).FirstOrDefault(); //mapping if (shoppingCart != null) { response.shoppingCartModel = new ShoppingCartModel { DiscountPrice = 0, TotalPrice = shoppingCart.ShoppingCartProducts.Sum(t => t.ProductCount * t.Product.Price), LastPrice = shoppingCart.ShoppingCartProducts.Sum(t => t.ProductCount * t.Product.Price) }; foreach (var item in shoppingCart.ShoppingCartProducts) { response.shoppingCartModel.cardProduct.Add( new ShoppingCartProductModel { CartDiscount = 0, MainImage = item.Product.ProductImages.FirstOrDefault().URL, Price = item.Product.Price, ProductName = item.Product.ProductName, ProductID = item.ProductID, ProductCount = item.ProductCount } ); } } response.SetStatus(Common.Constants.ResponseCode.SUCCESS); return(response); } catch (Exception ex) { response.SetStatus(Common.Constants.ResponseCode.FAILED_ON_DB_PROCESS, ex.Message); return(response); } }
/// <summary> /// new count 0 verilirse Product Sepetten Silinir. /// </summary> /// <param name="token"></param> /// <param name="productid"></param> /// <param name="newcount"></param> /// <returns></returns> public ShoppingCartResponse UpdateProductCountOfShoppingCart(string token, int productid, int newcount) { ShoppingCartResponse response = new ShoppingCartResponse(); ShoppingCart shoppingCart = new ShoppingCart(); try { shoppingCart = _repositoryShoppingCart.Get(t => t.Token == token).SingleOrDefault(); if (shoppingCart != null) { // Logic İçerisinde Dönülen dizi değiştiği için ToList() ile dönüldü foreach (ShoppingCartProduct item in shoppingCart.ShoppingCartProducts.ToList()) { if (newcount == 0 && item.ProductID == productid) { shoppingCart.ShoppingCartProducts.Remove(item); } else if (item.ProductID == productid) { item.ProductCount = newcount; } } _unitOfWork.SaveChanges(); } else { response.SetStatus(Common.Constants.ResponseCode.NOT_FOUND_SHOPPING_CART); return(response); } } catch (Exception exception) { response.SetStatus(Common.Constants.ResponseCode.FAILED_ON_DB_PROCESS, exception.Message); return(response); } response = GetShoppingCartofUser(token); return(response); }
public void SendResponse(ShoppingCartResponse response) { base.SendResponse(response); }
public IActionResult GetShoppingCartofUser([FromBody] string token) { ShoppingCartResponse response = _service.GetShoppingCartofUser(token); return(response.Code != (int)Constants.ResponseCode.SUCCESS ? StatusCode(500, response) : StatusCode(200, response)); }
public Task SendResponseAsync(ShoppingCartResponse response, CancellationToken cancellationToken = default) { return(base.SendResponseAsync(response, cancellationToken)); }
public ShoppingCartFinishedProcessState(ShoppingCartRequest request, ShoppingCartResponse response) { this.Request = request; this.Response = response; }
public ShoppingCartResponse Add(string token, int userid, int productid, int count) { ShoppingCartResponse response = new ShoppingCartResponse(); ShoppingCart shoppingCart = null; try { shoppingCart = _repositoryShoppingCart.Get(t => t.Token == token).FirstOrDefault(); if (shoppingCart != null) { //demekki sepeti var ShoppingCartProduct shoppingCartProduct = shoppingCart.ShoppingCartProducts.FirstOrDefault(t => t.ProductID == productid); if (shoppingCartProduct != null) { //bu urun zaten sepette var shoppingCartProduct.ProductCount += count; } else { //sepetim var ama urun sepette yok Product p = _repositoryProduct.Get(t => t.ID == productid).FirstOrDefault(); shoppingCart.ShoppingCartProducts.Add(new ShoppingCartProduct { ProductID = productid, ProductCount = count, Product = p }); } } else { shoppingCart = new ShoppingCart { Token = token, UserID = userid, ShoppingCartProducts = new List <ShoppingCartProduct>() { new ShoppingCartProduct { ProductID = productid, ProductCount = count } } }; _repositoryShoppingCart.Add(shoppingCart); } int result = _unitOfWork.SaveChanges(); if (result < 1) { response.SetStatus(Common.Constants.ResponseCode.SYSTEM_ERROR); return(response); } //**ef core crud işleminden sonra lazyloading aktif olarak bağlı olan productı getirmediği için kendimiz aldık foreach (var item in shoppingCart.ShoppingCartProducts) { if (item.Product == null) { item.Product = _repositoryProduct.Get(t => t.ID == item.ProductID).FirstOrDefault(); } } decimal total = shoppingCart.ShoppingCartProducts.Sum(t => t.ProductCount * t.Product.Price); response.shoppingCartModel = new ShoppingCartModel { DiscountPrice = 0, TotalPrice = total, LastPrice = total }; foreach (var item in shoppingCart.ShoppingCartProducts) { response.shoppingCartModel.cardProduct.Add( new ShoppingCartProductModel { CartDiscount = 0, MainImage = item.Product.ProductImages.FirstOrDefault().URL, Price = item.Product.Price, ProductName = item.Product.ProductName, ProductID = item.ProductID, ProductCount = item.ProductCount } ); } } catch (Exception ex) { response.SetStatus(Common.Constants.ResponseCode.FAILED_ON_DB_PROCESS, ex.Message); return(response); } response.SetStatus(Common.Constants.ResponseCode.SUCCESS); return(response); }