public string Create([Bind(Exclude = "Id")] Koap Model) { ApplicationDbContext db = new ApplicationDbContext(); string msg; try { if (ModelState.IsValid) { db.Koaps.Add(Model); db.SaveChanges(); msg = "Сохранено успешно"; } else { msg = "Данные не прошли проверку ввода"; } } catch (Exception ex) { msg = "Произошла ошибка:" + ex.Message; } return(msg); }
public string Delete(int Id) { ApplicationDbContext db = new ApplicationDbContext(); Koap Koaps = db.Koaps.Find(Id); db.Koaps.Remove(Koaps); db.SaveChanges(); return("Удалено успешно"); }
public async Task <ActionResult> CreateKoap([Bind(Include = "ID,Point,Part,Article,Name,Fabula,Prim,CourtID,Fam,Ima,Otch,DateRe,Vidvz")] Koap CreateKoap) { if (ModelState.IsValid) { db.Licos.Find(Session["IDLico"]).Koaps.Add(CreateKoap); //db.Addresses.Add(CreateAddress); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CourtID = new SelectList(db.Courts, "ID", "Name", CreateKoap.CourtID); return(View(CreateKoap)); }
public string Edit(Koap Model) { ApplicationDbContext db = new ApplicationDbContext(); string msg; try { if (ModelState.IsValid) { db.Entry(Model).State = EntityState.Modified; db.SaveChanges(); msg = "Сохранено успешно"; } else { msg = "Данные не прошли проверку ввода"; } } catch (Exception ex) { msg = "Произошла ошибка:" + ex.Message; } return(msg); }