Esempio n. 1
0
        public IHttpActionResult ListByZipCode(string zipCode)
        {
            ProductService productService = GeneralService.GetProductService();

            if (!string.IsNullOrWhiteSpace(zipCode))
            {
                return(Ok(productService.ListByZipCode(zipCode).AsEnumerable()));
            }
            return(Ok());
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
 public IHttpActionResult Get(long id)
 {
     try
     {
         ProductService productService = GeneralService.GetProductService();
         return(Ok(productService.Get(id)));
     }
     catch (Exception exception)
     {
         return(Json(new { Error = exception.Message }));
     }
 }
Esempio n. 4
0
        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)));
        }
Esempio n. 5
0
        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 });
        }
Esempio n. 6
0
        // Add new Product
        public IHttpActionResult Post(ProductViewModel viewModel)
        {
            ProductService productService = GeneralService.GetProductService();

            return(Ok(productService.Add(viewModel)));
        }
Esempio n. 7
0
        // List all the categories
        public IHttpActionResult ListCategories()
        {
            ProductService productService = GeneralService.GetProductService();

            return(Ok(productService.ListCategories()));
        }
Esempio n. 8
0
        public IHttpActionResult List(string searchText)
        {
            ProductService productService = GeneralService.GetProductService();

            return(Ok(productService.ListMatching(searchText).AsEnumerable()));
        }
Esempio n. 9
0
        public IHttpActionResult ListRecent()
        {
            ProductService productService = GeneralService.GetProductService();

            return(Ok(productService.ListRecent().AsEnumerable()));
        }
Esempio n. 10
0
        public IHttpActionResult ListTransactions(long id)
        {
            ProductService productService = GeneralService.GetProductService();

            return(Ok(productService.ListTransactions(id)));
        }
Esempio n. 11
0
        // Delete a Product
        public bool Delete(int id)
        {
            ProductService productService = GeneralService.GetProductService();

            return(productService.Delete(id));
        }
Esempio n. 12
0
        // GET: Product/Edit/5
        public ActionResult Edit(int id)
        {
            ProductService productService = GeneralService.GetProductService();

            return(View(productService.Get(id)));
        }
Esempio n. 13
0
        // GET: Product/Create
        public ActionResult Create()
        {
            ProductService productService = GeneralService.GetProductService();

            return(View());
        }
Esempio n. 14
0
        public JsonResult ListTransactions(long id)
        {
            ProductService productService = GeneralService.GetProductService();

            return(Json(productService.ListTransactions(id), JsonRequestBehavior.AllowGet));
        }
Esempio n. 15
0
        public JsonResult List(string name)
        {
            ProductService productService = GeneralService.GetProductService();

            return(Json(productService.ListMatching(name, 200), JsonRequestBehavior.AllowGet));
        }