public ActionResult AutoAdd(RcsDic t, bool Sure) { using (DicMainDb db = new DicMainDb()) { var list = db.RcsDic.Where(p => p.Name == t.Name).ToList(); if (list.Count == 0 || Sure) { db.RcsDic.Add(t); var table = db.RcsTable.Where(p => p.ID == t.TableID).FirstOrDefault(); table.Count = table.Count + 1; db.SaveChanges(); return(Json(new { success = true, Code = 0 })); } else { var table = (from row in list.AsEnumerable() where row.TableID == t.TableID select row).ToList(); if (table.Count == 0) { return(Json(new { success = false, Code = 1, Data = list.Select(p => p.ID).ToArray() })); } } } return(Json(new { success = false, Code = -1 })); }
public ActionResult NameCheck(RcsDic t, string time) { JsonResult result = Json(new { success = false, time = time }, JsonRequestBehavior.AllowGet); using (DicMainDb db = new DicMainDb()) { if (db.RcsDic.Where(p => p.ID != t.ID && p.Name == t.Name && p.TableID == t.TableID).Count() == 0) { result = Json(new { success = true, time = time }, JsonRequestBehavior.AllowGet); } } return(result); }
public ActionResult Detail() { RcsDic model = null; if (Request["ID"] != null && !string.IsNullOrWhiteSpace(Request["ID"])) { using (DicMainDb maindb = new DicMainDb()) { int ID = Convert.ToInt32(Request["ID"]); model = maindb.RcsDic.Where(p => p.ID == ID).FirstOrDefault(); } } return(View(model)); }
public ActionResult AutoMerge(string IDs, string Value) { using (DicMainDb db = new DicMainDb()) { string[] idarr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <int> idlist = new List <int>(); foreach (var id in idarr) { idlist.Add(Int32.Parse(id)); } var list = db.RcsDic.Where(p => idlist.Contains(p.ID)).ToList(); foreach (var t in list) { db.RcsDic.Attach(t); var entity = db.Entry(t); entity.State = System.Data.Entity.EntityState.Deleted; } var defalutTable = db.RcsTable.Where(p => p.Name == "defaultdic").First(); RcsDic newmodel = new RcsDic(); newmodel.Name = list[0].Name; newmodel.Value = Value; newmodel.Type = 1; newmodel.TableID = defalutTable.ID; db.RcsDic.Add(newmodel); db.SaveChanges(); string sql = @"update [dbo].[RcsTable] set Count=( select count(0) from [dbo].[RcsDic] t1 where t1.TableID=[RcsTable].ID )"; db.Database.ExecuteSqlCommand(sql); } return(Json(1)); }
public ActionResult EditAciton(RcsDic t) { using (DicMainDb maindb = new DicMainDb()) { if (t.ID == 0) { maindb.RcsDic.Add(t); var table = maindb.RcsTable.Where(p => p.ID == t.TableID).FirstOrDefault(); table.Count = table.Count + 1; } else { maindb.RcsDic.Attach(t); var entity = maindb.Entry(t); entity.State = System.Data.Entity.EntityState.Modified; } maindb.SaveChanges(); } return(Json(new { success = true })); }