Beispiel #1
0
 public JsonResult AddAdmin(Models.AdminModel model)
 {
     if (ModelState.IsValid)
     {
         IDAL.IAdminRepository adminRepository = EnterRepository.GetRepositoryEnter().GetAdminRepository;
         //判断权限名称是否已存在
         var result = adminRepository.LoadEntities(m => m.Mobile == model.Mobile.Trim()).FirstOrDefault();
         if (result == null)
         {
             Random rn   = new Random();
             string salt = rn.Next(10000, 99999).ToString() + rn.Next(10000, 99999).ToString();
             adminRepository.AddEntity(new Model.Admin()
             {
                 AuthoryId     = model.AuthoryId,
                 CreateTime    = DateTime.Now,
                 IsLogin       = model.IsLogin,
                 Mobile        = model.Mobile,
                 IsSuperAdmin  = 0,
                 LastLoginTime = DateTime.Now,
                 Salt          = salt,
                 Password      = MD5Helper.CreatePasswordMd5("ad" + model.Mobile.Substring(7, 4), salt)
             });
             //添加下操作记录
             PublicFunction.AddOperation(1, string.Format("添加管理员"), string.Format("添加管理员=={0}==成功", model.Mobile));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "添加管理员成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("添加管理员"), string.Format("添加管理员=={0}==失败", model.Mobile));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "添加管理员失败"
                 }));
             }
         }
         else
         {
             return(Json(new
             {
                 state = "error",
                 message = "手机号码已经存在了"
             }));
         }
     }
     else
     {
         return(Json(new { state = "error", message = "信息不完整" }));
     }
 }
Beispiel #2
0
 public JsonResult UpdateAdmin(Models.AdminModel model)
 {
     if (ModelState.IsValid)
     {
         IDAL.IAdminRepository adminRepository = EnterRepository.GetRepositoryEnter().GetAdminRepository;
         //判断权限名称是否已存在
         var result = adminRepository.LoadEntities(m => m.Mobile == model.Mobile.Trim()).FirstOrDefault();
         if (result != null && result.Id != model.Id)
         {
             return(Json(new
             {
                 state = "error",
                 message = "手机号码已经存在了"
             }));
         }
         else
         {
             Model.Admin admin = new Model.Admin()
             {
                 AuthoryId = model.AuthoryId,
                 IsLogin   = model.IsLogin,
                 Mobile    = model.Mobile,
                 Id        = model.Id
             };
             //清楚context中result对象
             adminRepository.Get(m => m.Id == model.Id);
             adminRepository.EditEntity(admin, new string[] { "AuthoryId", "IsLogin", "Mobile" });
             PublicFunction.AddOperation(1, string.Format("修改管理员"), string.Format("修改管理员=={0}==成功", model.Mobile));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "修改管理员成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("修改管理员"), string.Format("修改管理员=={0}==失败", model.Mobile));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "修改管理员失败"
                 }));
             }
         }
     }
     else
     {
         return(Json(new { state = "error", message = "信息不完整" }));
     }
 }