public CResult <bool> DeleteDeviceType(string deviceTypeID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("deviceTypeID", deviceTypeID); if (string.IsNullOrEmpty(deviceTypeID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.DeviceType.FirstOrDefault(t => t.ID == deviceTypeID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.DeviceTypeNotExist)); } if (context.Device.Any(t => t.DeviceTypeID == entity.ID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.DeviceTypeConatinDevice)); } entity.IsValid = false; var removeRels = context.DeviceTypeMaintainItemRel.Where(t => t.DeviceTypeID == entity.ID).ToList(); foreach (var item in removeRels) { context.DeviceTypeMaintainItemRel.Remove(item); } return(context.Save()); } }
public CResult <List <WebLog> > GetLogList(out int totalCount, string projectID, OperatTypeEnum?operatType = null, BusinessModelEnum?businessModel = null, string searchInfo = "", int pageIndex = 1, int pageSize = 10) { Expression <Func <Log, bool> > filter = t => t.ProjectID == projectID; if (operatType.HasValue) { filter = filter.And(t => t.OperatType == (int)operatType.Value); } if (businessModel.HasValue) { filter = filter.And(t => t.BusinessModel == (int)businessModel.Value); } if (string.IsNullOrWhiteSpace(searchInfo) == false) { searchInfo = searchInfo.Trim().ToUpper(); filter = filter.And(t => t.LogContent.ToUpper().Contains(searchInfo)); } using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { var result = context.Log.Where(filter).Page(out totalCount, pageIndex, pageSize, t => t.OperatDate, false).Select(t => new WebLog() { BusinessModel = (BusinessModelEnum)t.BusinessModel, Content = t.LogContent, LoginName = t.User.LoginName, Name = t.User.Name, OperatDate = t.OperatDate, OperatType = (OperatTypeEnum)t.OperatType }).ToList(); return(new CResult <List <WebLog> >(result)); } }
public CResult <bool> UpdateManufacturer(WebManufacturer model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.Manufacturer.FirstOrDefault(t => t.ID == model.ID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.ManufacturerNotExist)); } if (context.Manufacturer.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == entity.ProjectID && t.IsValid && t.ID != model.ID)) { return(new CResult <bool>(false, ErrorCode.ManufacturerNameIsExist)); } entity.Name = model.Name; entity.Note = model.Note; entity.Address = model.Address; entity.Contact = model.Contact; entity.Mobile = model.Mobile; entity.Phone = model.Phone; context.Entry(entity).State = EntityState.Modified; return(context.Save()); } }
public CResult <WebUser> GetUserInfoByUserID(string userID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("userID", userID); using (var context = new DeviceMgmtEntities()) { var entity = context.User.FirstOrDefault(t => t.IsValid && t.UserID == userID); if (entity != null) { var webUser = new WebUser() { ID = entity.UserID, Address = entity.Address, Email = entity.Email, LoginName = entity.LoginName, TelPhone = entity.Telephone, UserName = entity.Name, Moblie = entity.Moblie, Role = (RoleType)entity.Role, OrderClientID = entity.OrderClientID, }; LogHelper.Info("result", webUser); return(new CResult <WebUser>(webUser)); } else { return(new CResult <WebUser>(null, ErrorCode.DataNoExist)); } } }
public CResult <bool> DeleteMaintainItem(string maintainItemID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("maintainItemID", maintainItemID); if (string.IsNullOrEmpty(maintainItemID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.MaintainItem.FirstOrDefault(t => t.ID == maintainItemID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.DataNoExist)); } if (context.DeviceTypeMaintainItemRel.Any(t => t.MaintainItemID == entity.ID)) { return(new CResult <bool>(false, ErrorCode.MaintainItemUsed)); } entity.IsValid = false; return(context.Save()); } }
public CResult <bool> UpdateCompayLogo(HttpPostedFileBase file, string orderClientID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("orderClientID", orderClientID); using (var context = new DeviceMgmtEntities()) { var date = DateTime.Now.ToString("yyyy-MM-dd"); var fileName = string.Format("{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension(file.FileName)); var filePath = FileHelper.SaveFile(file, Path.Combine(SystemInfo.UploadFolder, date), fileName); if (string.IsNullOrEmpty(filePath) == false) { var orderClient = context.OrderClient.FirstOrDefault(t => t.IsValid && t.ID == orderClientID); if (string.IsNullOrEmpty(orderClient.LogoFile) == false) { FileHelper.DelFile(orderClient.LogoFile); } orderClient.LogoFile = filePath; } else { return(new CResult <bool>(false, ErrorCode.SaveFileFailed)); } if (context.SaveChanges() > 0) { return(new CResult <bool>(true)); } else { FileHelper.DelFile(filePath); } return(new CResult <bool>(true)); } }
public CResult <WebMaintainItem> GetMaintainItemByID(string maintainItemID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("maintainItemID", maintainItemID); if (string.IsNullOrEmpty(maintainItemID)) { return(new CResult <WebMaintainItem>(null, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.MaintainItem.FirstOrDefault(t => t.ID == maintainItemID && t.IsValid); if (entity == null) { return(new CResult <WebMaintainItem>(null, ErrorCode.DataNoExist)); } var model = new WebMaintainItem() { ID = entity.ID, Note = entity.Note, Name = entity.Name, CreateDate = entity.CreateDate, CreateUserID = entity.CreateUserID, CreateUserName = entity.User.Name, ProjectID = entity.ProjectID, }; LogHelper.Info("result", model); return(new CResult <WebMaintainItem>(model)); } }
public CResult <bool> UpdateUser(WebUser webUser) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("webUser", webUser); using (var context = new DeviceMgmtEntities()) { var entity = context.User.FirstOrDefault(t => t.UserID == webUser.ID); if (entity == null) { return(new CResult <bool>(false, ErrorCode.DataNoExist)); } entity.Address = webUser.Address; entity.Email = webUser.Email; entity.Name = webUser.UserName; entity.Telephone = webUser.TelPhone; entity.Moblie = webUser.Moblie; entity.Role = (int)webUser.Role; context.Entry(entity).State = EntityState.Modified; LoggerBLL.AddLog(context, webUser.CreateUserID, entity.ProjectID, OperatTypeEnum.修改, _businessModel, "用户名:" + entity.LoginName); return(context.Save()); } }
public static CResult <WebOrderClient> GetCompanyInfo(string orderClientID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("orderClientID", orderClientID); using (var context = new DeviceMgmtEntities()) { var entity = context.OrderClient.FirstOrDefault(t => t.ID == orderClientID); if (entity == null) { return(new CResult <WebOrderClient>(null, ErrorCode.DataNoExist)); } var webOrderClient = new WebOrderClient() { LogoFile = entity.LogoFile, CompanyContact = entity.CompanyContact, CompanyDescribe = entity.CompanyDescribe, CompanyName = entity.CompanyName, ID = entity.ID, }; LogHelper.Info("result", webOrderClient); return(new CResult <WebOrderClient>(webOrderClient)); } }
public CResult <bool> DeleteRepairRecord(string repairRecordID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("repairRecordID", repairRecordID); if (string.IsNullOrEmpty(repairRecordID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.RepairRecord.FirstOrDefault(t => t.ID == repairRecordID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.DataNoExist)); } entity.IsValid = false; var attachments = context.Attachment.Where(a => a.RelationID == entity.ID).ToList(); foreach (var attachment in attachments) { FileHelper.DelFile(attachment.FilePath); } return(context.Save()); } }
public CResult <bool> ChangePassword(string oldPassword, string newPassword, string userID, string operatorUserID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); if (string.IsNullOrWhiteSpace(newPassword) || string.IsNullOrWhiteSpace(oldPassword)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.User.FirstOrDefault(t => t.UserID == userID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.UserNotExist)); } if (string.Equals(oldPassword, entity.Password)) { entity.Password = newPassword; return(context.Save()); } else { return(new CResult <bool>(false, ErrorCode.ChangePasswordError)); } //LoggerBLL.AddLog(context, operatorUserID, entity.ProjectID, OperatTypeEnum.修改, _businessModel, "用户名:" + entity.LoginName); } }
public CResult <List <WebRepairRecord> > GetRepairRecordList(string deviceID, out int totalCount, string projectID, string searchInfo, DateTime?startTime = null, DateTime?endTime = null, int pageIndex = 1, int pageSize = 10, string orderby = null, bool ascending = false) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("deviceID", deviceID); LogHelper.Info("projectID", projectID); using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { Expression <Func <RepairRecord, bool> > filter = t => t.ProjectID == projectID && t.IsValid == true; if (string.IsNullOrWhiteSpace(searchInfo) == false) { searchInfo = searchInfo.Trim().ToUpper(); filter = filter.And(t => t.Operator.ToUpper().Contains(searchInfo) || t.Device.Name.Contains(searchInfo)); //filter = filter.And(t => t.Note.ToUpper().Contains(searchInfo)); } if (!string.IsNullOrWhiteSpace(deviceID)) { filter = filter.And(t => t.DeviceID == deviceID); } if (startTime.HasValue) { filter = filter.And(t => t.RepairDate >= startTime); } if (endTime.HasValue) { filter = filter.And(t => t.RepairDate <= endTime); } if (string.IsNullOrEmpty(orderby)) { orderby = "CreateDate"; ascending = false; } var temp = context.RepairRecord.Where(filter).Page(out totalCount, pageIndex, pageSize, orderby, ascending, true); var result = temp.Select(t => new WebRepairRecord() { ID = t.ID, Note = t.Note, DeviceID = t.DeviceID, DeviceName = t.Device.Name, Describe = t.Describe, Solution = t.Solution, Operator = t.Operator, RepairDate = t.RepairDate, CreateDate = t.CreateDate, CreateUserID = t.CreateUserID, CreateUserName = t.User.Name, ProjectID = t.ProjectID }).ToList(); LogHelper.Info("result", result); return(new CResult <List <WebRepairRecord> >(result)); } }
public CResult <bool> DeleteUserByID(string userID, string operatorUserID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("userID", userID); if (string.IsNullOrWhiteSpace(userID) || string.IsNullOrWhiteSpace(operatorUserID)) { return(new Common.CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.User.FirstOrDefault(t => t.IsValid && t.UserID == userID); if (entity != null) { if (entity.Role == (int)RoleType.项目管理员) { return(new CResult <bool>(false, ErrorCode.ProjectAdminCannotDelete)); } entity.IsValid = false; LoggerBLL.AddLog(context, userID, entity.ProjectID, OperatTypeEnum.除, _businessModel, "用户名:" + entity.LoginName); return(context.Save()); } else { return(new CResult <bool>(false, ErrorCode.DataNoExist)); } } }
public CResult <bool> DeleteManufacturer(string manufacturerID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("manufacturerID", manufacturerID); if (string.IsNullOrEmpty(manufacturerID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.Manufacturer.FirstOrDefault(t => t.ID == manufacturerID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.ManufacturerNotExist)); } if (context.Device.Any(t => t.ManufacturerID == entity.ID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.ManufactureConatinDevice)); } entity.IsValid = false; return(context.Save()); } }
public CResult <string> InsertMaintainRecord(WebMaintainRecord model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <string>("", ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <string>("", ErrorCode.ProjectNotExist)); } if (context.Device.Any(t => t.ID == model.DeviceID) == false) { return(new CResult <string>("", ErrorCode.DeviceNotExist)); } var entity = new MaintainRecord(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.MaintainDate = model.MaintainDate; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; entity.Operator = model.Operator; entity.DeviceID = model.DeviceID; context.MaintainRecord.Add(entity); foreach (var item in model.MaintainItems) { var relation = new MaintainRecordMaintainItemRel() { MaintainRecordID = entity.ID, MaintainItemID = item.ID }; context.MaintainRecordMaintainItemRel.Add(relation); } if (context.SaveChanges() > 0) { return(new CResult <string>(entity.ID)); } else { return(new CResult <string>("", ErrorCode.SaveDbChangesFailed)); } } }
public CResult <bool> InsertDeviceType(WebDeviceType model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <bool>(false, ErrorCode.ProjectNotExist)); } if (context.DeviceType.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.DeviceTypeNameIsExist)); } var maintainItemIDs = model.MaintainItems.Select(t => t.ID).ToList(); if (maintainItemIDs.Count > 0) { if (context.MaintainItem.Count(t => maintainItemIDs.Contains(t.ID) && t.IsValid && t.ProjectID == model.ProjectID) < maintainItemIDs.Count) { return(new CResult <bool>(false, ErrorCode.MaintainItemNotExist)); } } var entity = new DeviceType(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.Name = model.Name; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; foreach (var item in model.MaintainItems) { var relation = new DeviceTypeMaintainItemRel() { DeviceTypeID = entity.ID, MaintainItemID = item.ID }; context.DeviceTypeMaintainItemRel.Add(relation); } context.DeviceType.Add(entity); return(context.Save()); } }
public CResult <List <WebProject> > GetProjectList(out int totalCount, string userID, string searchInfo, int pageIndex = 1, int pageSize = 10, string orderby = null, bool ascending = false) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { Expression <Func <Project, bool> > filter = t => t.IsValid && t.CreateUserID == userID; if (string.IsNullOrWhiteSpace(searchInfo) == false) { searchInfo = searchInfo.Trim().ToUpper(); filter = filter.And(t => t.Name.ToUpper().Contains(searchInfo)); } if (string.IsNullOrEmpty(orderby)) { orderby = "CreateDate"; ascending = false; } var temp = context.Project.Where(filter).Page(out totalCount, pageIndex, pageSize, orderby, ascending, true); var result = temp.Select(t => new WebProject() { CreateDate = t.CreateDate, ID = t.ID, Note = t.Note, Name = t.Name, }).ToList(); var projectIDs = result.Select(t => t.ID).ToList(); var users = context.User.Where(t => t.Role == (int)RoleType.项目管理员 && projectIDs.Contains(t.ProjectID)).Select(user => new WebUser { ID = user.UserID, Address = user.Address, Email = user.Email, LoginName = user.LoginName, TelPhone = user.Telephone, Moblie = user.Moblie, UserName = user.Name, ProjectID = user.ProjectID }).ToList(); foreach (var user in users) { var project = result.FirstOrDefault(t => t.ID == user.ProjectID); project.WebUser = user; } LogHelper.Info("result", result); return(new CResult <List <WebProject> >(result)); } }
public List <DeviceModel> GetUserDevices() { List <DeviceModel> deviceModels = null; using (var ctx = new DeviceMgmtEntities()) { deviceModels = ctx.Devices.Where(ua => ua.UserAccount_ID == userId).Select(dvc => new DeviceModel() { DeviceID = dvc.ID, DeviceDescription = dvc.Description, DeviceName = dvc.Name, DeviceSerialNumber = dvc.DeviceSerialNr, DeviceType = dvc.DeviceType }).ToList <DeviceModel>(); } return(deviceModels); }
public static CResult <int> GetMaintainCount(string projectID) { using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { var today = DateTime.Now.Date; var result = context.Device.Count(t => t.ProjectID == projectID && t.IsValid && t.DeviceState != (int)DeviceStateEnum.报废 && t.MaintainDate.HasValue && t.MaintainDate.Value <= today); LogHelper.Info("result", result); return(new CResult <int>(result)); } }
public CResult <WebRepairRecord> GetRepairRecordByID(string repairRecordID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("repairRecordID", repairRecordID); if (string.IsNullOrEmpty(repairRecordID)) { return(new CResult <WebRepairRecord>(null, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.RepairRecord.FirstOrDefault(t => t.ID == repairRecordID && t.IsValid); if (entity == null) { return(new CResult <WebRepairRecord>(null, ErrorCode.DataNoExist)); } var model = new WebRepairRecord() { ID = entity.ID, Note = entity.Note, DeviceID = entity.DeviceID, DeviceName = entity.Device.Name, Operator = entity.Operator, RepairDate = entity.RepairDate, CreateDate = entity.CreateDate, CreateUserID = entity.CreateUserID, CreateUserName = entity.User.Name, ProjectID = entity.ProjectID, Solution = entity.Solution, Describe = entity.Describe, }; var attachments = context.Attachment.Where(a => a.RelationID == entity.ID).ToList(); foreach (var attachment in attachments) { model.Attachments.Add(new WebAttachment() { DisplayName = attachment.DisplayName, FilePath = attachment.FilePath, ID = attachment.ID, Note = attachment.Note }); } LogHelper.Info("result", model); return(new CResult <WebRepairRecord>(model)); } }
public CResult <bool> InsertProject(WebProject webProject) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("webProject", webProject); using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.CreateUserID == webProject.CreateUserID && t.Name.ToUpper() == webProject.Name.ToUpper() && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.ProjectNameIsExist)); } var project = new Project(); project.CreateDate = DateTime.Now; project.CreateUserID = webProject.CreateUserID; project.ID = Guid.NewGuid().ToString(); project.Name = webProject.Name; project.Note = webProject.Note; project.IsValid = true; var webUser = webProject.WebUser; webUser.CreateUserID = webProject.CreateUserID; var userLoginName = webUser.LoginName.ToUpper(); if (context.User.Any(t => t.LoginName.ToUpper() == userLoginName)) { return(new CResult <bool>(false, ErrorCode.LoginNameIsExist)); } var entity = new User() { UserID = Guid.NewGuid().ToString(), Password = webUser.Pwd, LoginName = webUser.LoginName, Name = webUser.UserName, ProjectID = project.ID, Address = webUser.Address, Telephone = webUser.TelPhone, CreateDate = DateTime.Now, CreateUserID = webUser.CreateUserID, Email = webUser.Email, IsValid = true, Role = (int)RoleType.项目管理员, OrderClientID = webUser.OrderClientID }; context.Project.Add(project); context.User.Add(entity); return(context.Save()); } }
public static void AddLog(DeviceMgmtEntities context, string userID, string projectID, OperatTypeEnum operatType, BusinessModelEnum businessModel, string content) { var entity = new Log() { BusinessModel = (int)businessModel, ID = Guid.NewGuid().ToString(), LogContent = content, OperatType = (int)operatType, UserID = userID, OperatDate = DateTime.Now, ProjectID = projectID }; context.Log.Add(entity); }
//public CResult<List<WebRepairRecord>> GetRepairRecordListByDeviceID(string deviceID, out int totalCount, string searchInfo, int pageIndex = 1, int pageSize = 10, string orderby = null, bool ascending = false) //{ // LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); // LogHelper.Info("deviceID", deviceID); // using (DeviceMgmtEntities context = new DeviceMgmtEntities()) // { // Expression<Func<RepairRecord, bool>> filter = t => t.DeviceID == deviceID && t.IsValid == true; // if (string.IsNullOrWhiteSpace(searchInfo) == false) // { // searchInfo = searchInfo.Trim().ToUpper(); // filter = filter.And(t => t.Note.ToUpper().Contains(searchInfo)); // } // var temp = context.RepairRecord.Where(filter).Page(out totalCount, pageIndex, pageSize, orderby, ascending, true); // var result = temp.Select(t => new WebRepairRecord() // { // ID = t.ID, // Note = t.Note, // DeviceID = t.DeviceID, // DeviceName = t.Device.Name, // Operator = t.Operator, // RepairDate = t.RepairDate, // CreateDate = t.CreateDate, // CreateUserID = t.CreateUserID, // CreateUserName = t.User.Name, // ProjectID = t.ProjectID // }).ToList(); // LogHelper.Info("result", result); // return new CResult<List<WebRepairRecord>>(result); // } //} public CResult <string> InsertRepairRecord(WebRepairRecord model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <string>(string.Empty, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <string>(string.Empty, ErrorCode.ProjectNotExist)); } if (context.Device.Any(t => t.ID == model.DeviceID) == false) { return(new CResult <string>(string.Empty, ErrorCode.DeviceNotExist)); } var entity = new RepairRecord(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.RepairDate = model.RepairDate; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; entity.Operator = model.Operator; entity.DeviceID = model.DeviceID; entity.Solution = model.Solution; entity.Describe = model.Describe; context.RepairRecord.Add(entity); if (context.SaveChanges() > 0) { return(new CResult <string>(entity.ID)); } else { return(new CResult <string>("", ErrorCode.SaveDbChangesFailed)); } } }
public CResult <WebUser> VerifyPassword(string userName, string password) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); using (var context = new DeviceMgmtEntities()) { var user = context.User.FirstOrDefault(t => t.IsValid && t.LoginName == userName && t.Password == password); if (user == null) { return(new CResult <WebUser>(null, ErrorCode.UserNameOrPasswordWrong)); } WebUser webUser = new WebUser() { ID = user.UserID, Address = user.Address, Email = user.Email, LoginName = user.LoginName, TelPhone = user.Telephone, Moblie = user.Moblie, UserName = user.Name, Role = (RoleType)user.Role, OrderClientID = user.OrderClientID, }; if (webUser.Role == RoleType.超级管理员 || webUser.Role == RoleType.客户管理员) { } else { var project = context.Project.FirstOrDefault(t => t.IsValid && t.ID == user.ProjectID); if (project == null) { return(new CResult <WebUser>(null, ErrorCode.UserNameOrPasswordWrong)); } webUser.ProjectID = project.ID; } LogHelper.Info("result", webUser); return(new CResult <WebUser>(webUser)); } }
public CResult <WebDevice> GetDeviceByID(string DeviceID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("DeviceID", DeviceID); if (string.IsNullOrEmpty(DeviceID)) { return(new CResult <WebDevice>(null, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.Device.FirstOrDefault(t => t.ID == DeviceID && t.IsValid); if (entity == null) { return(new CResult <WebDevice>(null, ErrorCode.DataNoExist)); } var model = new WebDevice() { ID = entity.ID, Num = entity.Num, Note = entity.Note, Name = entity.Name, DeviceState = (DeviceStateEnum)entity.DeviceState, CreateDate = entity.CreateDate, CreateUserID = entity.CreateUserID, CreateUserName = entity.User.Name, ProjectID = entity.ProjectID, DeviceTypeID = entity.DeviceTypeID, DeviceTypeName = entity.DeviceType.Name, MaintainDate = entity.MaintainDate, ManufacturerID = entity.ManufacturerID, ManufacturerName = string.IsNullOrEmpty(entity.ManufacturerID) ? "" : entity.Manufacturer.Name, ProductDate = entity.ProductDate, SupplierID = entity.SupplierID, SupplierName = string.IsNullOrEmpty(entity.SupplierID) == false ? "" : entity.Supplier.Name }; LogHelper.Info("result", model); return(new CResult <WebDevice>(model)); } }
public CResult <List <WebUser> > GetUserList(out int totalCount, string projectID, string userID, string searchInfo, int pageIndex = 1, int pageSize = 10, string orderby = null, bool ascending = false) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); totalCount = 0; if (string.IsNullOrWhiteSpace(projectID)) { return(new Common.CResult <List <WebUser> >(new List <WebUser>())); } Expression <Func <User, bool> > filter = t => t.IsValid && t.ProjectID == projectID && t.UserID != userID; if (string.IsNullOrWhiteSpace(searchInfo) == false) { searchInfo = searchInfo.Trim().ToUpper(); filter = filter.And(t => t.Name.ToUpper().Contains(searchInfo) || t.LoginName.ToUpper().Contains(searchInfo)); } if (string.IsNullOrEmpty(orderby)) { orderby = "CreateDate"; ascending = false; } using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { var userList = context.User.Where(filter).Page(out totalCount, pageIndex, pageSize, orderby, ascending, true); var result = userList.Select(t => new WebUser() { ID = t.UserID, Address = t.Address, CreateDate = t.CreateDate, CreateUserID = t.CreateUserID, CreateUserName = context.User.FirstOrDefault(u => u.UserID == u.UserID).Name, Email = t.Email, LoginName = t.LoginName, TelPhone = t.Telephone, UserName = t.Name, Role = (RoleType)t.Role }).ToList(); return(new CResult <List <WebUser> >(result)); } }
public void InitDB() { Membership.DeleteUser("SuperAdmin"); using (var context = new DeviceMgmtEntities()) { foreach (var item in Enum.GetNames(typeof(RoleType))) { if (Roles.RoleExists(item) == false) { Roles.CreateRole(item); } } User superAdmin; if (Membership.FindUsersByName("SuperAdmin").Count == 0) { var member = Membership.CreateUser("SuperAdmin", "111111"); Roles.AddUserToRole("SuperAdmin", RoleType.超级管理员.ToString()); superAdmin = new User() { Address = "", CreateDate = DateTime.Now, CreateUserID = "", Email = "", IsValid = true, LoginName = "SuperAdmin", ProjectID = "", UserID = member.ProviderUserKey.ToString(), Name = "SuperAdmin", Telephone = "", Moblie = "" }; context.User.Add(superAdmin); } else { superAdmin = context.User.FirstOrDefault(t => t.LoginName == "SuperAdmin"); } context.SaveChanges(); } }
public CResult <List <WebMaintainItem> > GetMaintainItemListByDeviceID(string deviceID) { using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { var result = (from device in context.Device where device.ID == deviceID join rel in context.DeviceTypeMaintainItemRel on device.DeviceTypeID equals rel.DeviceTypeID join item in context.MaintainItem on rel.MaintainItemID equals item.ID select new WebMaintainItem() { ID = item.ID, Name = item.Name, }).ToList(); LogHelper.Info("result", result); return(new CResult <List <WebMaintainItem> >(result)); } }
public CResult <bool> InsertDevice(WebDevice model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <bool>(false, ErrorCode.ProjectNotExist)); } if (context.Device.Any(t => t.Num.ToUpper() == model.Num.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.DeviceNumIsExist)); } var entity = new Device(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.Num = model.Num; entity.Name = model.Name; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; entity.DeviceTypeID = model.DeviceTypeID; entity.MaintainDate = model.MaintainDate; entity.ManufacturerID = model.ManufacturerID; entity.ProductDate = model.ProductDate; entity.SupplierID = model.SupplierID; entity.DeviceState = (int)model.DeviceState; context.Device.Add(entity); return(context.Save()); } }
public CResult <List <WebManufacturer> > GetManufacturerList(out int totalCount, string projectID, string searchInfo, int pageIndex = 1, int pageSize = 10, string orderby = null, bool ascending = false) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); using (DeviceMgmtEntities context = new DeviceMgmtEntities()) { Expression <Func <Manufacturer, bool> > filter = t => t.ProjectID == projectID && t.IsValid == true; if (string.IsNullOrWhiteSpace(searchInfo) == false) { searchInfo = searchInfo.Trim().ToUpper(); filter = filter.And(t => t.Name.ToUpper().Contains(searchInfo) || t.Contact.ToUpper().Contains(searchInfo)); } if (string.IsNullOrEmpty(orderby)) { orderby = "CreateDate"; ascending = false; } var temp = context.Manufacturer.Where(filter).Page(out totalCount, pageIndex, pageSize, orderby, ascending, true); var result = temp.Select(t => new WebManufacturer() { ID = t.ID, Name = t.Name, Address = t.Address, Contact = t.Contact, Mobile = t.Mobile, Phone = t.Phone, Note = t.Note, CreateDate = t.CreateDate, CreateUserID = t.CreateUserID, CreateUserName = t.User.Name, ProjectID = t.ProjectID }).ToList(); LogHelper.Info("result", result); return(new CResult <List <WebManufacturer> >(result)); } }