/// <summary> /// convert Api response into list basket view model /// </summary> /// <param name="apiResponse"></param> /// <returns></returns> private IList <BasketItemViewModel> Convert_ApiResponse_ToListBaskitemViewModel(string apiResponse) { GenericResponseRepository <BasketItem> response = new GenericResponseRepository <BasketItem>(); IList <BasketItem> basketItem = response.Convert_to_List(apiResponse); return(_mapper.Map <IList <BasketItemViewModel> >(basketItem)); }
/// <summary> /// Get single product by product Id /// </summary> /// <param name="productId"></param> /// <returns>single product view model</returns> public ProductViewModel GetProductById(int productId) { string apiResponse = _iGetRequestManager.SendRequest(_iGetApiUrls.GetProductByIdApiUrl(productId), "", "", false, HttpRequestContentType.ApplicationJson.GetDescription(), null); if (apiResponse == null) { return(null); } GenericResponseRepository <Product> response = new GenericResponseRepository <Product>(); Product product = response.Convert(apiResponse); return(_mapper.Map <Product, ProductViewModel>(product)); }
/// <summary> /// Get product catelog /// </summary> /// <returns>List of all product view model</returns> public IList <ProductViewModel> GetProducts() { string apiResponse = _iGetRequestManager.SendRequest(_iGetApiUrls.ProductsApiUrl, "", "", false, HttpRequestContentType.ApplicationJson.GetDescription(), null); if (apiResponse == null) { return(null); } GenericResponseRepository <Product> response = new GenericResponseRepository <Product>(); IList <Product> product = response.Convert_to_List(apiResponse); return(_mapper.Map <IList <ProductViewModel> >(product)); }
/// <summary> /// Add Item into Basket /// </summary> /// <param name="productId"></param> /// <param name="quantity"></param> /// <returns></returns> public BasketItemViewModel AddItemintoBasket(int productId, int quantity, int userId) { BasketItem basketItem = new BasketItem(); basketItem.ProductId = productId; basketItem.Quantity = quantity; basketItem.UserId = userId; string jsonsContent = JsonConvert.SerializeObject(basketItem); string apiResponse = _iPostRequestManager.SendRequest(_iGetApiUrls.PostBasketItem, jsonsContent, "", "", false, HttpRequestContentType.ApplicationJson.GetDescription(), null); if (apiResponse == null) { return(null); } GenericResponseRepository <BasketItem> response = new GenericResponseRepository <BasketItem>(); basketItem = response.Convert(apiResponse); return(_mapper.Map <BasketItemViewModel>(basketItem)); }