/// <summary> /// 修改报警名称 /// </summary> /// <param name="name">需要修改的报警名称</param> /// <param name="propertyName">需要修改的指定属性名称</param> /// <param name="value">属性修改后的值</param> public void EditAlarmGroup(string name, string propertyName, object value) { CheckAlarmGroupSetIsNull(); var alarmGroup = FindAlarmGroupByName(name); if (alarmGroup == null) { throw new Exception("需要修改的报警不存在"); } ObjectCopier.CopyProperty(alarmGroup, propertyName, value); RealTimeRepositoryBase.RtDbContext.SaveAllChanges(); }
/// <summary> /// 根据变量的属性名称修改变量的该项属性 /// </summary> /// <param name="absolutePath">变量绝对路径名</param> /// <param name="propertyName">要被修改的变量的属性名</param> /// <param name="value">修改的值</param> public virtual VariableBase EditVariable(string absolutePath, string propertyName, object value) { VariableBase variable = VariableRepository.FindVariableByPath(absolutePath); if (variable == null) { throw new Exception("需要修改的变量不存在"); } if (propertyName == "Name") { if (IsExistName(propertyName, variable.ParentGroup)) { throw new Exception("变量名称已存在,不能修改"); } } ObjectCopier.CopyProperty(variable, propertyName, value); RealTimeRepositoryBase.RtDbContext.SaveAllChanges(); return(variable); }
/// <summary> /// 字典的最大不好 就是不允许空。当初这个方法设计有问题。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <param name="dictionary"></param> public void Update <T>(int id, Dictionary <string, object> dictionary) { using (var loveDb = new LoveDb()) { object obj = null; switch (typeof(T).Name) { case "User": obj = loveDb.Users.SingleOrDefault(n => n.UserId == id); break; case "BaseInfo": obj = loveDb.BaseInfos.SingleOrDefault(n => n.Id == id); break; case "Requirement": obj = loveDb.Requirements.SingleOrDefault(n => n.Id == id); break; case "DetailInfo": obj = loveDb.DetailInfos.SingleOrDefault(n => n.Id == id); break; case "LoveView": obj = loveDb.LoveViews.SingleOrDefault(n => n.Id == id);; break; case "InfoStatistic": obj = loveDb.InfoStatistics.SingleOrDefault(n => n.Id == id); break; case "UserHot": obj = loveDb.UserHots.SingleOrDefault(n => n.Id == id); break; case "Praise": obj = loveDb.Praises.SingleOrDefault(n => n.Id == id); break; case "State": obj = loveDb.States.SingleOrDefault(n => n.Id == id); break; case "Iamgbox": obj = loveDb.Iamgboxes.SingleOrDefault(n => n.Id == id); break; case "Message": obj = loveDb.Messages.SingleOrDefault(n => n.Id == id); break; case "LoginLog": obj = loveDb.LoginLogs.SingleOrDefault(n => n.Id == id); break; case "Role": obj = loveDb.Roles.SingleOrDefault(n => n.Id == id); break; case "Hello": obj = loveDb.Hellos.SingleOrDefault(n => n.Id == id); break; case "RoleLog": obj = loveDb.RoleLogs.SingleOrDefault(n => n.Id == id); break; case "Authority": obj = loveDb.Authoritys.SingleOrDefault(n => n.Id == id); break; case "AdminStatistic": obj = loveDb.AdminStatistics.SingleOrDefault(n => n.Id == id); break; case "Topic": obj = loveDb.Topics.SingleOrDefault(n => n.Id == id); break; } if (obj == null) { return; } foreach (var element in dictionary) { ObjectCopier.CopyProperty(obj, element.Key, element.Value); } loveDb.SaveChanges(); } }