Exemplo 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);
         }
     }
 }
Exemplo n.º 2
0
        public void MarkDeleted(long id)
        {
            var data = GetById(id);

            data.IsDeleted = true;
            db.SaveChanges();
        }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
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);
         }
     }
 }
Exemplo n.º 7
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();
     }
 }
Exemplo n.º 8
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();
     }
 }
Exemplo n.º 9
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);
         }
     }
 }