public IHttpActionResult ListByZipCode(string zipCode) { ProductService productService = GeneralService.GetProductService(); if (!string.IsNullOrWhiteSpace(zipCode)) { return(Ok(productService.ListByZipCode(zipCode).AsEnumerable())); } return(Ok()); }
public IHttpActionResult ListByPosition(float?latitude, float?longitude) { ProductService productService = GeneralService.GetProductService(); if (latitude.HasValue && longitude.HasValue) { LocationService service = new LocationService(); var zipCodes = service.GetZipCodesInRange(latitude.Value, longitude.Value).Select(x => x.Zipcode).ToList(); return(Ok(productService.ListByZipCodes(zipCodes).ToList())); } return(Ok()); }
public IHttpActionResult Get(long id) { try { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.Get(id))); } catch (Exception exception) { return(Json(new { Error = exception.Message })); } }
public ActionResult Details(int id) { ProductService productService = GeneralService.GetProductService(); ActiveUser user = ActiveUser.GetActiveUser(); if (user.IsAuthenticated) { var transaction = productService.GetLeadingOffer(id); if (transaction == null) { ViewBag.Message = "There are no offers yet!"; } else { ViewBag.Message = (transaction.CustomerID == user.CustomerId) ? "You are leading this offer!" : "You are not leading!"; } } return(View(productService.Get(id))); }
public ActionResult MakeOffer(int id, string offerPrice, long?customerId) { string message = string.Empty, newPrice = offerPrice; bool result = true; try { if ((customerId ?? 0) == 0) { customerId = ActiveUser.GetActiveUser().CustomerId; } if (!customerId.HasValue || customerId.Value == 0) { throw new Exception("You are not authorized to submit an offer."); } ProductService productService = GeneralService.GetProductService(); Decimal price = 0; if (Decimal.TryParse(offerPrice, out price)) { productService.CreateOffer(id, price, customerId.Value); message = string.Format("Offer for ${0:2} submitted.", offerPrice); newPrice = price.ToString("C"); } else { message = string.Format("Offer price ${0} is invalid.", offerPrice); } } catch (Exception ex) { message = string.Format("Error submitting the offer; {0}", ex.Message); result = false; } return(Json(new { result = result, message = message, newPrice = newPrice })); //return RedirectToAction("Details", new { id = id }); }
// Add new Product public IHttpActionResult Post(ProductViewModel viewModel) { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.Add(viewModel))); }
// List all the categories public IHttpActionResult ListCategories() { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.ListCategories())); }
public IHttpActionResult List(string searchText) { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.ListMatching(searchText).AsEnumerable())); }
public IHttpActionResult ListRecent() { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.ListRecent().AsEnumerable())); }
public IHttpActionResult ListTransactions(long id) { ProductService productService = GeneralService.GetProductService(); return(Ok(productService.ListTransactions(id))); }
// Delete a Product public bool Delete(int id) { ProductService productService = GeneralService.GetProductService(); return(productService.Delete(id)); }
// GET: Product/Edit/5 public ActionResult Edit(int id) { ProductService productService = GeneralService.GetProductService(); return(View(productService.Get(id))); }
// GET: Product/Create public ActionResult Create() { ProductService productService = GeneralService.GetProductService(); return(View()); }
public JsonResult ListTransactions(long id) { ProductService productService = GeneralService.GetProductService(); return(Json(productService.ListTransactions(id), JsonRequestBehavior.AllowGet)); }
public JsonResult List(string name) { ProductService productService = GeneralService.GetProductService(); return(Json(productService.ListMatching(name, 200), JsonRequestBehavior.AllowGet)); }