示例#1
0
        public ActionResult EditCity(City cityToUpdate)
        {
            int id = cityToUpdate.Id;
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var city = rdb.cities.Where(s => s.Id == id).FirstOrDefault();
                    city.City = cityToUpdate.Name;
                    rdb.Entry(city).State = System.Data.Entity.EntityState.Modified;
                    rdb.SaveChanges();
                    string message = "Successfully Saved!";
                    if (Request.IsAjaxRequest())
                    {
                        return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

                    }
                    else
                    {
                        return null;
                    }
                    //return Content(Boolean.TrueString);
                }
                catch
                {//TODO: Log error	
                    return Json(false);
                    //return Content(Boolean.FalseString);
                }
            }
        }
示例#2
0
 public ActionResult CreateCity(City city)
 {
     string message = "";
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         try
         {
             rdb.cities.Add(new cities { City = city.Name });
             rdb.SaveChanges();
             var id = rdb.cities.Where(s => s.City.Equals(city.Name)).Select(s => s.Id);
             message = "Successfully Saved!" + id.ToString();
         }
         catch
         {
             message = "Error! Please try again!";
         }
         if (Request.IsAjaxRequest())
         {
             return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
         }
         else
         {
             return PartialView();
         }
     }
 }