public string GetValue(string configName, string defaultValue) { if (string.IsNullOrEmpty(defaultValue)) { throw new Exception(string.Format("配置项{0}不能为空", configName)); } using (var dal = new BaseDal()) { var p = dal.Config.Find(configName); if (p == null) { dal.Config.Add(new ConfigDefinition() { Name = configName, Value = defaultValue, Comment = "" }); dal.SaveChanges(); return(defaultValue); } else { if (string.IsNullOrEmpty(p.Value)) { throw new Exception(string.Format("配置项{0}不能为空", p.Name)); } return(p.Value); } } }
public void Update(string functionId, string administratorId, IList <string> tableColumnIds) { using (var dal = new BaseDal()) { var list = dal.TableColumnAndAdmin.Where(o => ((o.FunctionId == functionId) && (o.AdministratorId == administratorId))); var tableColumnList = dal.TableColumn.Where(o => o.FunctionId == functionId); dal.TableColumnAndAdmin.RemoveRange(list); foreach (var p in tableColumnIds) { var tableColumn = tableColumnList.SingleOrDefault(o => o.TableColumnId == p); if (tableColumn == null) { continue; } dal.TableColumnAndAdmin.Add(new TableColumnAndAdminDefinition() { TableColumnId = p, FunctionId = functionId, AdministratorId = administratorId, }); } dal.SaveChanges(); } }
public void Update(string roleId, IList <string> functionIds, IList <string> commandIds) { using (var dal = new BaseDal()) { var oldRoleAndFunction = dal.RoleAndFunction.Where(o => o.RoleId == roleId); dal.RoleAndFunction.RemoveRange(oldRoleAndFunction); var oldRoleAndCommand = dal.RoleAndCommand.Where(o => o.RoleId == roleId); dal.RoleAndCommand.RemoveRange(oldRoleAndCommand); foreach (var p in functionIds) { dal.RoleAndFunction.Add(new RoleAndFunctionDefinition() { RoleId = roleId, FunctionId = p }); } foreach (var p in commandIds) { dal.RoleAndCommand.Add(new RoleAndCommandDefinition() { RoleId = roleId, CommandId = p }); } dal.SaveChanges(); } }
public virtual void Add(T p) { using (var bll = new BaseDal()) { bll.Set <T>().Add(p); bll.SaveChanges(); } }
public virtual void Update(T p) { using (var bll = new BaseDal()) { bll.Entry(p).State = EntityState.Modified; bll.SaveChanges(); } }
public void RemoveById(string functionId) { using (var dal = new BaseDal()) { var p = dal.Function.Find(functionId); dal.Function.Remove(p); dal.SaveChanges(); } }
public virtual void Remove(T p) { using (var bll = new BaseDal()) { bll.Set <T>().Attach(p); bll.Set <T>().Remove(p); bll.SaveChanges(); } }
//public void ExecuteNonQuery(string sql) //{ // using (var dal = new BaseDal()) // { // dal.Database.ExecuteNonQuery(sql); // } //} public void Clear() { using (var dal = new BaseDal()) { var list = (from o in dal.Set <T>() select o).ToList(); dal.Set <T>().RemoveRange(list); dal.SaveChanges(); } }
public void SetValue(string configName, string value) { GetValue(configName, value); using (var dal = new BaseDal()) { var p = dal.Config.Find(configName); p.Value = value; dal.Entry(p).State = EntityState.Modified; dal.SaveChanges(); } }
public void DeleteByFunctionId(string functionId) { using (var dal = new BaseDal()) { var list = dal.TableColumnAndAdmin.Where(o => o.FunctionId == functionId).ToList(); if (list.Count() > 0) { dal.TableColumnAndAdmin.RemoveRange(list); dal.SaveChanges(); } } }
public void AndOrUpdate(TableColumnDefinition p) { using (var dal = new BaseDal()) { var q = dal.TableColumn.SingleOrDefault(o => (o.FunctionId == p.FunctionId) && (o.Field == p.Field)); if (q == null) { dal.TableColumn.Add(p); } else { q.Align = p.Align; q.Width = p.Width; q.Name = p.Name; q.Format = p.Format; q.Index = p.Index; dal.Entry(q).State = EntityState.Modified; } dal.SaveChanges(); } }
public void AndOrUpdate(CommandDefinition p) { using (var dal = new BaseDal()) { var q = dal.Command.SingleOrDefault(o => (o.FunctionId == p.FunctionId) && (o.OnClick == p.OnClick)); if (q == null) { dal.Command.Add(p); } else { q.Href = p.Href; q.Class = p.Class; q.IconCls = p.IconCls; q.Plain = p.Plain; q.CommandName = p.CommandName; q.Index = p.Index; q.Location = p.Location; dal.Entry(q).State = EntityState.Modified; } dal.SaveChanges(); } }