Example #1
0
        public JsonResult AddRating(string providerPhone, string rating)
        {
            try
            {
                if (string.IsNullOrEmpty(providerPhone) || string.IsNullOrEmpty(rating))
                    return Json(new { Error = "Invalid input", status = 405 }, JsonRequestBehavior.AllowGet);

                int providerRating;
                if (!int.TryParse(rating, out providerRating) && providerRating > 0)
                    return Json(new { Error = "Invalid rating", status = 405 }, JsonRequestBehavior.AllowGet);

                IHomeFoodRepository repo = new HomeFoodRepository();
                repo.UpdateRating(providerPhone, providerRating);

                return Json(new { status = 200 }, JsonRequestBehavior.AllowGet);

            }

            catch (Exception ex)
            {
                return Json(new { Error = ex.Message, status = 400 }, JsonRequestBehavior.AllowGet);
            }
        }