示例#1
0
 public void InsertOrUpdate(News news)
 {
     if (news.Id == default(int)) {
         // New entity
         context.News.Add(news);
     } else {
         // Existing entity
         context.Entry(news).State = EntityState.Modified;
     }
 }
示例#2
0
        public JsonResult Edit(News news)
        {
            if (ModelState.IsValid)
            {
                newsRepository.InsertOrUpdate(news);
                newsRepository.Save();

                return Json(new { result = true, item = news }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { result = false, errors = ModelState.Values.SelectMany(t => t.Errors.Select(t1 => t1.ErrorMessage)) };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
        }