public async Task<ActionResult> AddAsync(UserInfo model) { var user = await AppUsers.GetCurrentAsync(this.Tenant).ConfigureAwait(true); if (!user.IsAdministrator) { return this.AccessDenied(); } if (!this.ModelState.IsValid) { return this.InvalidModelState(this.ModelState); } if (model.Password != model.ConfirmPassword) { return this.Failed("Confirm password does not match with the supplied password", HttpStatusCode.BadRequest); } try { await DAL.Users.CreateUserAsync(this.Tenant, user.UserId, model).ConfigureAwait(true); return this.Ok("OK"); } catch (Exception ex) { return this.Failed(ex.Message, HttpStatusCode.InternalServerError); } }
public static async Task CreateUserAsync(string tenant, int userId, UserInfo model) { using (var db = DbProvider.Get(FrapidDbServer.GetSuperUserConnectionString(tenant), tenant).GetDatabase()) { string encryptedPassword = EncryptPassword(model.Password); var user = new User { Email = model.Email, Password = encryptedPassword, OfficeId = model.OfficeId, RoleId = model.RoleId, Name = model.Name, Phone = model.Phone, AuditTs = DateTimeOffset.UtcNow, AuditUserId = userId }; await db.InsertAsync("account.users", "user_id", true, user).ConfigureAwait(false); } }