Esempio n. 1
0
 public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         bool exists = serives.GetAll().Any(e => e.PhoneNum == phoneNum);
         if (exists)
         {
             throw new ArgumentException("账号已存在");
         }
         else
         {
             string          salt  = CommonHelper.CreateVerifyCode(4);
             string          pwd   = CommonHelper.CalcMD5(password + salt);
             AdminUserEntity admin = new AdminUserEntity()
             {
                 CityId          = cityId,
                 Email           = email,
                 Name            = name,
                 PhoneNum        = phoneNum,
                 LoginErrorTimes = 0,
                 PasswordSalt    = salt,
                 PasswordHash    = pwd
             };
             db.AdminUsers.Add(admin);
             db.SaveChanges();
             return(admin.Id);
         }
     }
 }
Esempio n. 2
0
 public IEnumerable <AdminUserDTO> GetAll(long?cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         return(serives.GetAll().Include(e => e.City).AsNoTracking().Select(item => DTO(item)).ToList());
     }
 }
Esempio n. 3
0
 public void MarkDeleted(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         serives.MarkDeleted(id);
     }
 }
Esempio n. 4
0
 public void Deleted(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CityEntity> service = new BaseService <CityEntity>(db);
         service.MarkDeleted(id);
     }
 }
Esempio n. 5
0
 public IEnumerable <AttachmentDTO> GetAll()
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AttachmentEntity> serives = new BaseService <AttachmentEntity>(db);
         return(serives.GetAll().AsNoTracking().ToList().Select(item => DTO(item)));
     }
 }
Esempio n. 6
0
 public void RecordLoginError(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> service = new BaseService <AdminUserEntity>(db);
         var data = service.GetById(id);
         data.LoginErrorTimes = data.LoginErrorTimes++;
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 public void AddAdminLog(long adminUserId, string message)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         AdminLogEntity adminLog = new AdminLogEntity()
         {
             Msg    = message,
             UserId = adminUserId
         };
         db.AdminLogs.Add(adminLog);
     }
 }
Esempio n. 8
0
 public CityDTO GetById(long cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CityEntity> service = new BaseService <CityEntity>(db);
         var data = service.GetById(cityId);
         if (data == null)
         {
             return(null);
         }
         return(DTO(data));
     }
 }
Esempio n. 9
0
 public bool HasPermission(long adminUserId, string permissionName)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> service = new BaseService <AdminUserEntity>(db);
         var data = service.GetAll().Include(e => e.Roles).SingleOrDefault(e => e.Id == adminUserId);
         if (data == null)
         {
             throw new ArgumentException("没有id为" + adminUserId + "的管理员用户");
         }
         return(data.Roles.SelectMany(x => x.Permissions).Any(e => e.Name == permissionName));
     }
 }
Esempio n. 10
0
 public bool CheckLogin(string phoneNum, string password)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         var data = serives.GetAll().AsNoTracking().SingleOrDefault(e => e.PhoneNum == phoneNum);
         if (data == null)
         {
             return(false);
         }
         return(data.PasswordHash == CommonHelper.CalcMD5(password + data.PasswordSalt));
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 获取Settings表的所有数据
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public IEnumerable <SettingsDTO> GetSettings()
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <SettingEntity> serives = new BaseService <SettingEntity>(db);
         return(serives.GetAll().Select(item => new SettingsDTO()
         {
             Id = item.Id,
             Name = item.Name,
             Value = item.Value,
             CreateDateTime = item.CreateDateTime
         }).ToList());
     }
 }
Esempio n. 12
0
 public void Edit(long id, string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CityEntity> service = new BaseService <CityEntity>(db);
         var data = service.GetById(id);
         if (data == null)
         {
             throw new ArgumentException("此城市" + id + "不存在");
         }
         data.Name = name;
         db.SaveChanges();
     }
 }
Esempio n. 13
0
 public IEnumerable <IdNameDTO> GetAll(string typeName)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <IdNameEntity> serives = new BaseService <IdNameEntity>(db);
         return(serives.GetAll().Where(e => e.TypeName == typeName).ToList().Select(item => new IdNameDTO()
         {
             Id = item.Id,
             Name = item.Name,
             TypeName = item.TypeName,
             CreateDateTime = item.CreateDateTime
         }));
     }
 }
Esempio n. 14
0
 public AdminUserDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         var data = serives.GetAll().Include(e => e.City).AsNoTracking().SingleOrDefault(e => e.Id == id);
         if (data == null)
         {
             return(null);
         }
         else
         {
             return(DTO(data));
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// 获取值
 /// </summary>
 /// <param name="name">要查询的名称</param>
 /// <returns></returns>
 public string GetValue(string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <SettingEntity> serives = new BaseService <SettingEntity>(db);
         var data = serives.GetAll().AsNoTracking().SingleOrDefault(e => e.Name == name);
         if (data == null)
         {
             return(null);
         }
         else
         {
             return(data.Value);
         }
     }
 }
Esempio n. 16
0
 public IEnumerable <AttachmentDTO> GetHouseId(long houseID)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseEntity> serives = new BaseService <HouseEntity>(db);
         var data = serives.GetAll().Include(e => e.Attachments).AsNoTracking().SingleOrDefault(e => e.Id == houseID);
         if (data == null)
         {
             throw new ArgumentException("找不到" + houseID + "的数据");
         }
         else
         {
             return(data.Attachments.Select(item => DTO(item)));
         }
     }
 }
Esempio n. 17
0
 public void AddAdminUserRole(long id, long[] roleId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         var roles = service.GetAll().Include(e => e.Permissions).Where(e => roleId.Contains(e.Id)).ToList();
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(db);
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("不存在id为" + id + "的用户");
         }
         foreach (var item in roles)
         {
             user.Roles.Add(item);
         }
         db.SaveChanges();
     }
 }
Esempio n. 18
0
 public AdminUserDTO GetByPhoneNum(string phoneNum)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         var data = serives.GetAll().Include(e => e.City).AsNoTracking().Where(e => e.PhoneNum == phoneNum);
         if (data.Count() <= 0)
         {
             return(null);
         }
         else if (data.Count() == 1)
         {
             return(DTO(data.SingleOrDefault()));
         }
         else
         {
             throw new ArgumentException("存在多个" + phoneNum + "的用户");
         }
     }
 }
Esempio n. 19
0
 public void SetValue(string name, string value)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <SettingEntity> serives = new BaseService <SettingEntity>(db);
         var data = serives.GetAll().SingleOrDefault(e => e.Name == name);
         if (data == null)
         {
             SettingEntity setting = new SettingEntity()
             {
                 Name  = name,
                 Value = value
             };
             db.Settings.Add(setting);
         }
         else
         {
             data.Value = value;
         }
         db.SaveChanges();
     }
 }
Esempio n. 20
0
 public long AddCity(string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CityEntity> serives = new BaseService <CityEntity>(db);
         var result = serives.GetAll().Any(e => e.Name == name);
         if (result)
         {
             throw new ArgumentException("参数已存在");
         }
         else
         {
             CityEntity city = new CityEntity()
             {
                 Name = name
             };
             db.Cities.Add(city);
             db.SaveChanges();
             return(city.Id);
         }
     }
 }
Esempio n. 21
0
 public void UpdateAdminUser(long id, string name, string phoneNum, string password, string email, long?cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         var data = serives.GetById(id);
         if (data == null)
         {
             throw new ArgumentException("数据不存在");
         }
         if (!string.IsNullOrEmpty(password))
         {
             data.PasswordHash = CommonHelper.CalcMD5(password + data.PasswordSalt);
         }
         data.Name     = name;
         data.PhoneNum = phoneNum;
         data.Name     = name;
         data.Email    = email;
         data.CityId   = cityId;
         db.SaveChanges();
     }
 }
Esempio n. 22
0
 public long AddIdName(string typeName, string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <IdNameEntity> serives = new BaseService <IdNameEntity>(db);
         bool esixts = serives.GetAll().Any(e => e.TypeName == typeName && e.Name == name);
         if (esixts)
         {
             throw new ArgumentException("此数据已存在");
         }
         else
         {
             IdNameEntity entity = new IdNameEntity()
             {
                 Name     = name,
                 TypeName = typeName
             };
             db.IdNames.Add(entity);
             db.SaveChanges();
             return(entity.Id);
         }
     }
 }
Esempio n. 23
0
 public IdNameDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <IdNameEntity> serives = new BaseService <IdNameEntity>(db);
         var data = serives.GetById(id);
         if (data == null)
         {
             throw new ArgumentException("没有此数据");
         }
         else
         {
             IdNameDTO idName = new IdNameDTO()
             {
                 Id             = data.Id,
                 Name           = data.Name,
                 TypeName       = data.TypeName,
                 CreateDateTime = data.CreateDateTime
             };
             return(idName);
         }
     }
 }
Esempio n. 24
0
 public BaseService(WarmHomeContext db)
 {
     this.db = db;
 }