public ReturnModel <string> Post([FromBody] AddToCartRequestModel model) { var productToBeAdded = _productService.Get(model.ProductId).Data; var cart = _cartSessionService.GetCart(); var result = _cartService.AddToCart(cart, productToBeAdded, model.Quantity); _cartSessionService.SetCart(cart); return(result); }
public HttpResponseMessage addToCart(AddToCartRequestModel addToCartRequestModel) { CartProvider cartProvider = new CartProvider(); ErrorModel errorModel = null; var cartStatus = cartProvider.addToCart(addToCartRequestModel, out errorModel); APIResponseModel aPIResponseModel = new APIResponseModel(); aPIResponseModel.Response = cartStatus; aPIResponseModel.Error = errorModel; return(Request.CreateResponse(HttpStatusCode.OK, aPIResponseModel)); }
public AddToCartResponseModel addToCart(AddToCartRequestModel addToCartRequestModel, out ErrorModel errorModel) { errorModel = null; try { Cart cartHelper = new Cart(); return(cartHelper.addToCart(addToCartRequestModel, out errorModel)); } catch (Exception) { return(null); } }
public void Add_Product_With_Invalid_Quantity_Should_Give_Errors_In_Response(int quantity) { AddToCartRequestModel addToCartRequestModel = GetAddToCartRequestModel(); addToCartRequestModel.Quantity = quantity; AddToCartResponseModel expectedResponse = new AddToCartResponseModel(); var errMsg = "Quantity should be greater than 0"; expectedResponse.Errors.Add(errMsg); var response = _addToCartInteractor.Execute(addToCartRequestModel); response.Should().NotBeNull(); response.Errors.Any().Should().Be(true); response.Errors.First().Should().Be(errMsg); }
public void Add_Product_With_Invalid_ProductType_Should_Give_Errors_In_Response(string productType) { AddToCartRequestModel addToCartRequestModel = GetAddToCartRequestModel(); addToCartRequestModel.ProductType = productType; AddToCartResponseModel expectedResponse = new AddToCartResponseModel(); var errMsg = "Product does not exists in the system"; expectedResponse.Errors.Add(errMsg); _productRepository.Setup(x => x.GetProduct(It.IsAny <string>(), It.IsAny <string>())).Returns((Product)null); var response = _addToCartInteractor.Execute(addToCartRequestModel); response.Should().NotBeNull(); response.Errors.Any().Should().Be(true); response.Errors.First().Should().Be(errMsg); }
public AddToCartResponseModel addToCart(AddToCartRequestModel addToCartRequestModel, out ErrorModel errorModel) { errorModel = null; AddToCartResponseModel addToCartResponseModel = null; SqlConnection connection = null; try { using (connection = new SqlConnection(Database.getConnectionString())) { SqlCommand command = new SqlCommand(SqlCommands.SP_addToCart, connection); command.CommandType = System.Data.CommandType.StoredProcedure; #region Command Parameters command.Parameters.AddWithValue("itemId", addToCartRequestModel.itemId); command.Parameters.AddWithValue("addedBy", addToCartRequestModel.addedby); command.Parameters.AddWithValue("qty", addToCartRequestModel.quantity); #endregion connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { addToCartResponseModel = new AddToCartResponseModel(); addToCartResponseModel.StatusCode = reader["StatusCode"].ToString(); addToCartResponseModel.StatusMessage = reader["StatusMessage"].ToString(); } command.Dispose(); return(addToCartResponseModel); } } catch (Exception e) { errorModel = new ErrorModel(); errorModel.ErrorMessage = e.Message; return(null); } finally { if (connection != null) { connection.Close(); } } }