/// <summary> /// Posts the specified cart view model. /// </summary> /// <param name="addToCartRequestViewModel">The add to cart request view model.</param> /// <returns></returns> public static HttpStatusCode Post(AddToCartRequestViewModel addToCartRequestViewModel) { try { HttpContent content = new ObjectContent <AddToCartRequestViewModel>(addToCartRequestViewModel, JsonFormatterHelper.Instance.JsonMediaTypeFormatterInstance); var response = ABCApiHelper.Post(CartConfiguration.ApiBaseUrl, "Cart/AddtoCart", content); return(response.StatusCode); } catch (Exception e) { throw e; } }
/// <summary> /// Addtoes the cart. /// </summary> /// <param name="cartItem">The cart item.</param> /// <returns></returns> public async Task <AddtoCartResponse> AddtoCart(AddToCartRequestViewModel cartItem) { try { var client = _requestClientCreator.Create <AddtoCartRequest, AddtoCartResponse>(); var createRequest = new AddtoCartRequest(cartItem.ProductId, cartItem.CustomerId); var response = await client.Request(createRequest); return(response); } catch (Exception ex) { throw ex; } }
public async Task <HttpResponseMessage> AddtoCart(AddToCartRequestViewModel cartItem) { if (ModelState.IsValid) { var result = await _service.AddtoCart(cartItem); if (result.Success) { return(Request.CreateResponse(HttpStatusCode.OK, result.Message)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, result.Message)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } }