public async Task <bool> DeleteInviteUser(CompanyInviteUsersList user) { try { UserInvites userInvites = await this.therapistContext.UserInvites.Where(x => x.UserInviteGuid == user.UserInviteGuid).FirstOrDefaultAsync(); userInvites.IsDeleted = true; await this.therapistContext.SaveChangesAsync(); return(true); } catch (Exception ex) { throw ex; } }
public async Task <string> AddUser(AddUserRequest requestInfo) { using (var a = contextFactory.CreateDbContext()) { var requestingUser = await a.Users.Where(x => x.Id == httpContext.GetCurrentUserId()).FirstOrDefaultAsync(); if (requestingUser.Admin == false) { throw new ArgumentException("Error: You aren't an administrator"); } // Checks for existing if (await a.Users.FirstOrDefaultAsync(x => x.Email == requestInfo.Email && x.OrganizationId == requestingUser.OrganizationId) != null) { throw new ArgumentException("There is already a user with this email in this organization"); } // Creates and adds a user int parentOrgId = await a.Users.Where(x => x.Id == httpContext.GetCurrentUserId()).Select(x => x.OrganizationId).FirstOrDefaultAsync(); var user = new Users(parentOrgId, requestInfo.Email, requestInfo.FirstName, requestInfo.LastName); // Creates a unique token string token = Guid.NewGuid().ToString("N"); var userInvite = new UserInvites() { UserId = user.Id, InviteToken = token, }; user.UserInvites = userInvite; await a.AddAsync(user); await a.SaveChangesAsync(); return(token); } }