//To retrieve the product types public static ProductTypesResponse GetProductTypes() { ProductTypesResponse productTypesResponse = new ProductTypesResponse(); auctionEntities = new AuctionSystemEntities(); //retrieve producttypes from productTypes table in database to a list var dbProductTypes = auctionEntities.product_type.ToList(); //if list is null set fault as no product types if (dbProductTypes == null) { productTypesResponse.Fault = new Error { Code = ErrorCodes.NoProductTypes, Message = "There are no Products" }; return(productTypesResponse); } productTypesResponse.ProductTypes = new List <ProductTypes>(); //loop through each item in list foreach (product_type dbProductType in dbProductTypes) { //create new products object and set values for properties ProductTypes productType = new ProductTypes() { ProductTypeId = dbProductType.id, ProductType = dbProductType.type }; productTypesResponse.ProductTypes.Add(productType); } return(productTypesResponse); }
public ActionResult ProductTypes() { LoginModelResponse customerinfo = (LoginModelResponse)Session["Customer"]; if (customerinfo == null) { return(RedirectToActionPermanent("Index", "Login")); } ViewBag.LoginSuccess = "True"; ProductTypesResponse productTypesResponse = new ProductTypesResponse(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiBaseUrl"]); //HTTP GET var responseMessageTask = client.GetAsync("api/Product/GetProductTypes"); responseMessageTask.Wait(); var responseMessage = responseMessageTask.Result; if (responseMessage.IsSuccessStatusCode) { var responseContentTask = responseMessage.Content.ReadAsAsync <ProductTypesResponse>(); responseContentTask.Wait(); productTypesResponse = responseContentTask.Result; } else //web api sent error response { //log response status here.. ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); return(View("Index", productTypesResponse)); } } return(View("Index", productTypesResponse)); }
public IHttpActionResult GetProductTypes() { ProductTypesResponse products = CustomerProduct.GetProductTypes(); return(Ok(products)); }