public long AddNew(AdminUserAddDto model) { AdminUserEntity adminUser = model.EntityMap(); string pwdHash = "123456".CalcMd5(); adminUser.PasswordHash = pwdHash; adminUser.CreateDateTime = DateTime.Now; using (YersDbContext ctx = new YersDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); ctx.AdminUsers.Add(adminUser); bool exists = bs.GetAll().Any(u => u.LoginName == model.LoginName); if (exists) { throw new ArgumentException("登录名已经存在" + model.LoginName); } ctx.AdminUsers.Add(adminUser); ctx.SaveChanges(); return(adminUser.Id); } }
public async Task <int> AddAdminUserAsync(AdminUserAddDto adminUserAdd) { try { var args = new Dictionary <string, object> { { "@Email", adminUserAdd.Email }, { "@IsActive", adminUserAdd.IsActive }, { "@CreatedBy", adminUserAdd.CreatedBy }, { "@CreatedDate", DateTime.UtcNow }, { "@LastModificationDate", DateTime.UtcNow }, { "@FirstName", adminUserAdd.FirstName }, { "@LastName", adminUserAdd.LastName }, { "@ModifiedBy", adminUserAdd.ModifiedBy }, }; var newAdminUserId = await ExecuteScalarAsync <int>(AddAdminUserSpName, args); return(newAdminUserId); } catch (Exception ex) { throw ex; } }
public async Task <int> AddAdminUserAsync(AdminUserAddDto adminUserAdd) { try { var result = await _adminUserRepository.AddAdminUserAsync(adminUserAdd); return(result); } catch (Exception e) { throw e; } }
public ActionResult Add(AdminUserAddDto adminUser) { if (adminUser.Id <= 0) { AdminUserService.AddNew(adminUser); AdminLogService.AddNew($"添加管理员:{adminUser.LoginName}"); return(Json(new AjaxResult { Result = true, Msg = "管理员添加成功" })); } AdminUserService.Update(adminUser); AdminLogService.AddNew($"修改管理员【LoginName:{adminUser.LoginName},Id:{adminUser.Id}】"); return(Json(new AjaxResult { Result = true, Msg = "管理员修改成功" })); }
public async Task <IHttpActionResult> AddAdminUserAsync([FromBody] AdminUserAddDto dto) { try { if (dto == null) { throw new InvalidParameterValueException(BodyShouldNotBeNull); } if (dto.CreatedBy == null) { dto.CreatedBy = HttpContext.Current.User.GetUserEmail()?.ToLower(); } var result = await PostAsync(_adminUserManager.AddAdminUserAsync, dto); return(result); } catch (Exception e) { throw e; } }
public void Update(AdminUserAddDto dto) { using (YersDbContext ctx = new YersDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); bool exists = bs.GetAll().Any(u => u.LoginName == dto.LoginName && u.Id != dto.Id); if (exists) { throw new ArgumentException("登录名已经存在" + dto.LoginName); } var model = bs.GetById(dto.Id); model.LoginName = dto.LoginName; model.UserName = dto.UserName; model.Email = dto.Email; model.PhoneNumber = dto.PhoneNumber; ctx.SaveChanges(); } }
public static AdminUserEntity EntityMap(this AdminUserAddDto model) { return(Mapper.Map <AdminUserEntity>(model)); }