public bool Delete(string Id, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { // var isExist = (from mp in cxt.G_ModulePermission from ro in cxt.G_RoleOrganization where mp.ModuleID.Equals(Id) && mp.RoleID.Equals(ro.Id) select new { mp, ro }).FirstOrDefault(); if (isExist != null) { result = false; msg = "This module is already in use and unable to be deleted."; } else { G_Module itemDelete = (from tb in cxt.G_Module where tb.Id == Id select tb).FirstOrDefault(); cxt.G_Module.Remove(itemDelete); cxt.SaveChanges(); } } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Insert(ModuleModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { G_Module item = new G_Module(); item.Id = Guid.NewGuid().ToString(); item.Name = model.Name; item.Controller = model.Controller; item.ParentID = model.ParentID == null ? "" : model.ParentID; item.CreatedDate = DateTime.Now; item.CreatedUser = model.CreatedUser; item.ModifiedDate = DateTime.Now; item.ModifiedUser = model.ModifiedUser; item.IndexNum = model.IndexNum; cxt.G_Module.Add(item); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }