/// <summary> /// 保存设备 /// </summary> /// <param name="d"></param> /// <returns></returns> public static int SaveDevice(Device d) { try { WebDBEntities2 Entity = new WebDBEntities2(); Device device = Entity.Devices.FirstOrDefault(p => p.Imei == d.Imei); if (device != null)//如果设备已存在 { device.Status = d.Status; device.IconId = d.IconId; device.UserId = d.UserId; device.APIDeviceId = d.APIDeviceId > 0 ? d.APIDeviceId : device.APIDeviceId; device.APIDeviceModel = d.APIDeviceModel > 0 ? d.APIDeviceModel : device.APIDeviceModel; } else { Entity.Devices.Add(d); } Entity.SaveChanges(); return(0); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(1); } }
/// <summary> /// 保存医生信息 /// </summary> /// <param name="d"></param> /// <returns></returns> public static int SaveDoctor(Doctor d) { try { WebDBEntities2 Entity = new WebDBEntities2(); Doctor doctor = Entity.Doctors.FirstOrDefault(p => p.UserId == d.UserId); if (doctor != null) { doctor.Hospital = d.Hospital; doctor.DoctorInfo = d.DoctorInfo; doctor.Subject = d.Subject; doctor.Position = d.Position; } else { Entity.Doctors.Add(d); } return(Entity.SaveChanges()); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(0); } }
/// <summary> /// 保存指令下发记录 /// </summary> /// <param name="cl"></param> public static void SaveCmdLog(CmdLog cl) { WebDBEntities2 entity = new WebDBEntities2(); entity.CmdLogs.Add(cl); entity.SaveChanges(); }
/// <summary> /// 保存用户 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int SaveUser(User u) { try { WebDBEntities2 Entity = new WebDBEntities2(); if (u.Id > 0) { User entity = Entity.Users.FirstOrDefault(p => p.Id == u.Id); entity.UserName = u.UserName; entity.PhoneNum = u.PhoneNum; entity.Email = u.Email; entity.Sex = u.Sex; entity.BirthDate = u.BirthDate; entity.UserInfo = u.UserInfo; entity.Status = u.Status; entity.BingDoctorId = u.BingDoctorId; entity.HeartMin = u.HeartMin; entity.HeartMax = u.HeartMax; entity.BloodMax = u.BloodMax; entity.BloodMin = u.BloodMin; entity.BloodMax2 = u.BloodMax2; entity.BloodMin2 = u.BloodMin2; } else { Entity.Users.Add(u); } return(Entity.SaveChanges()); } catch (Exception ex) { LogHelper.ErrorLog(ex.Message); return(0); } }
/// <summary> /// 保存系统公告 修改和新增 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int SaveNotice(Notice n) { try { WebDBEntities2 Entity = new WebDBEntities2(); Notice notice = Entity.Notices.FirstOrDefault(p => p.Id == n.Id); if (notice != null)//修改 { notice.Content = n.Content; notice.CreateUser = n.CreateUser; notice.CreateUserName = n.CreateUserName; notice.Status = n.Status; notice.Title = n.Title; } else {//新增 Entity.Notices.Add(n); } return(Entity.SaveChanges()); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(0); } }
/// <summary> ///更新用户头像 /// </summary> /// <param name="userId">用户id</param> /// <param name="imgId">图片id</param> /// <returns></returns> public static int UpdateUserHeadImg(int userId, int imgId) { WebDBEntities2 Entity = new WebDBEntities2(); User _u = Entity.Users.FirstOrDefault(p => p.Id == userId); _u.HeadImgId = imgId; return(Entity.SaveChanges()); }
/// <summary> /// 更新队列时间 /// </summary> /// <param name="queue"></param> public static void UpdateQueueTime(CmdQueue queue) { WebDBEntities2 entity = new WebDBEntities2(); CmdQueue q = entity.CmdQueues.FirstOrDefault(p => p.APIDeviceId == queue.APIDeviceId && p.CmdCode == queue.CmdCode); q.LastExecTime = DateTime.Now.AddMinutes(q.ExceTime ?? 0); entity.SaveChanges(); }
/// <summary> /// 逻辑删除用户 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static int DeleteUser(int userId) { WebDBEntities2 Entity = new WebDBEntities2(); User user = Entity.Users.FirstOrDefault(p => p.Id == userId); user.Status = (int)Status.Deleted; return(Entity.SaveChanges()); }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="userId"></param> /// <param name="pwd"></param> /// <returns></returns> public static User EditPwd(int userId, string pwd) { WebDBEntities2 Entity = new WebDBEntities2(); User user = Entity.Users.FirstOrDefault(p => p.Id == userId); user.Pwd = pwd; Entity.SaveChanges(); return(user); }
/// <summary> /// 根据用户id删除医生 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static int DeleteDoctorByUserId(int userId) { WebDBEntities2 Entity = new WebDBEntities2(); Doctor d = Entity.Doctors.FirstOrDefault(p => p.UserId == userId); Entity.Doctors.Remove(d); return(Entity.SaveChanges()); }
/// <summary> /// 移除队列 /// </summary> /// <param name="cmdCode"></param> /// <param name="deviceId"></param> public static void DelCmdQueue(string cmdCode, int deviceId) { WebDBEntities2 entity = new WebDBEntities2(); CmdQueue q = entity.CmdQueues.FirstOrDefault(p => p.APIDeviceId == deviceId && p.CmdCode == cmdCode); if (q != null) { entity.CmdQueues.Remove(q); entity.SaveChanges(); } }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int UpdateUser(User u) { WebDBEntities2 Entity = new WebDBEntities2(); User user = Entity.Users.First(p => p.Id == u.Id); user.APIToken = u.APIToken; user.APIUserId = u.APIUserId; user.Email = u.Email; user.LastLoginIp = u.LastLoginIp; user.LastLoginTime = u.LastLoginTime; return(Entity.SaveChanges()); }
/// <summary> /// 将用户从医生中解绑 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string UnBindUser(int userId) { WebDBEntities2 Entity = new WebDBEntities2(); User user = Entity.Users.FirstOrDefault(p => p.Id == userId); if (user != null) { user.BingDoctorId = null; } Entity.SaveChanges(); return(user.LoginName); }
/// <summary> /// 添加权限 /// </summary> /// <param name="userType">用户类型</param> /// <param name="pId">菜单id 数组</param> /// <param name="userName">操作的管理员登陆账号</param> /// <returns></returns> public static int AddPower(int userType, int[] pId, string userName = "") { WebDBEntities2 Entity = new WebDBEntities2(); foreach (int i in pId) { if (Entity.UserTypeToMenus.FirstOrDefault(p => p.UserTypeId == userType && p.MenuId == i) == null) { Entity.UserTypeToMenus.Add(new UserTypeToMenu { UserTypeId = userType, MenuId = i, Created = DateTime.Now, Note = userName + "操作", Status = (int)Status.Normal }); } } Entity.SaveChanges(); return(Entity.SaveChanges()); }
/// <summary> /// 保存操作记录 /// </summary> /// <param name="log"></param> /// <returns></returns> public static int SaveWebLog(WebLog log) { try { WebDBEntities2 Entity = new WebDBEntities2(); Entity.WebLogs.Add(log); int res = Entity.SaveChanges(); return(res); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(0); } }
/// <summary> /// 删除权限 /// </summary> /// <param name="userType">用户类型</param> /// <param name="pId">菜单id 数组</param> /// <param name="userName">操作的管理员登陆账号</param> /// <returns></returns> public static int DelPower(int userType, int[] pId, string userName = "") { WebDBEntities2 Entity = new WebDBEntities2(); foreach (int i in pId) { var _power = Entity.UserTypeToMenus.FirstOrDefault(p => p.UserTypeId == userType && p.MenuId == i); if (_power != null) { Entity.UserTypeToMenus.Remove(_power); } } return(Entity.SaveChanges()); }
/// <summary> /// 删除公告 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int DelNotice(Notice n) { try { WebDBEntities2 Entity = new WebDBEntities2(); Entity.Notices.Remove(Entity.Notices.First(p => p.Id == n.Id)); Entity.SaveChanges(); return(1); } catch (Exception ex) { LogHelper.WriteLog(ex); return(0); } }
/// <summary> /// 根据id删除用户菜单 /// </summary> /// <param name="id"></param> /// <returns></returns> public static int DeleteUserMenu(UserMenu um) { try { WebDBEntities2 Entity = new WebDBEntities2(); Entity.UserMenus.Remove(Entity.UserMenus.First(p => p.Id == um.Id)); Entity.SaveChanges(); return(1); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(0); } }
/// <summary> /// 删除设备 /// </summary> /// <param name="deviceId"></param> /// <returns></returns> public static int DelDevice(int deviceId) { try { WebDBEntities2 Entity = new WebDBEntities2(); Device d = Entity.Devices.FirstOrDefault(p => p.Id == deviceId); Entity.Devices.Remove(d); Entity.SaveChanges(); return(0); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(1); } }
/// <summary> /// 保存系统公告 /// </summary> /// <param name="config"></param> /// <returns></returns> public static int SaveSysConfig(SysConfig config) { WebDBEntities2 Entity = new WebDBEntities2(); try { SysConfig s = Entity.SysConfigs.FirstOrDefault(); s.ICP = config.ICP; s.JsVersion = config.JsVersion; s.SysName = config.SysName; return(Entity.SaveChanges()); } catch (Exception ex) { LogHelper.ErrorLog(ex); return(0); } }
/// <summary> /// 添加指令执行队列,定时下发指令 /// </summary> /// <param name="queue"></param> public static void SaveCmdQueue(CmdQueue queue) { WebDBEntities2 entity = new WebDBEntities2(); CmdQueue q = entity.CmdQueues.FirstOrDefault(p => p.APIDeviceId == queue.APIDeviceId && p.CmdCode == queue.CmdCode); if (q != null) { q.Model = queue.Model; q.IMEI = queue.IMEI; q.LastExecTime = queue.LastExecTime; q.Param = queue.Param; q.Notice = queue.Notice; q.ExceTime = queue.ExceTime; } else { entity.CmdQueues.Add(queue); } entity.SaveChanges(); }
/// <summary> /// 保存图片 /// </summary> /// <param name="img"></param> /// <returns></returns> public static int SaveImg(Img img) { WebDBEntities2 Entity = new WebDBEntities2(); var _i = Entity.Imgs.FirstOrDefault(p => p.ObjId == img.ObjId && p.ImgType == img.ImgType); if (_i != null) { _i.ImgPath = img.ImgPath; _i.ImgType = img.ImgType; _i.ClickUrl = img.ClickUrl; _i.Alt = img.Alt; _i.ObjId = img.ObjId; _i.Note = img.Note; _i.UploadTime = DateTime.Now; img.Id = _i.Id; } else { Entity.Imgs.Add(img); } Entity.SaveChanges(); return(img.Id); }
/// <summary> /// 保存用户菜单 /// </summary> /// <param name="um"></param> /// <returns></returns> public static int SaveMenu(UserMenu um) { WebDBEntities2 Entity = new WebDBEntities2(); int res = 0; try { if (um.Id <= 0) { Entity.UserMenus.Add(um); } else { UserMenu _um = Entity.UserMenus.FirstOrDefault(p => p.Id == um.Id); _um.MenuName = um.MenuName; _um.MenuLevel = um.MenuLevel; _um.MenuCode = um.MenuCode; _um.Note = um.Note; _um.ParentId = um.ParentId; _um.Url = um.Url; _um.Icon = um.Icon; //Entity.UserMenus.Attach(um); // context.Entry(user).State = System.Data.Entity.EntityState.Modified; } Entity.SaveChanges(); res = um.Id; //超级管理员有所有菜单的权限 PowerLogic.AddPower(1, new int[] { um.Id }, ""); } catch (Exception ex) { res = 0; LogHelper.ErrorLog(ex.Message); } return(res); }