public async Task <OccupantResponse> InsertOccupantQuery(IDbConnection db, OccupantInsertRequest occupant) { OccupantResponse insertedOccupant = await db.QueryFirstAsync <OccupantResponse>( sql : "[Houses].[Occupants_Insert]", param : occupant, commandType : CommandType.StoredProcedure ); return(insertedOccupant); }
public async Task <OccupantResponse> UpdateOccupant(OccupantUpdateRequest occupant) { return(await asyncConnection(occupant.UserId, occupant.OccupantId, async db => { OccupantResponse updatedOccupant = await db.QueryFirstAsync <OccupantResponse>( sql: "[Houses].[Occupants_Update]", param: occupant, commandType: CommandType.StoredProcedure ); return updatedOccupant; })); }
public async Task <bool> InviteOccupant(OccupantInviteRequest invite) { // TODO: Send invite email! return(await asyncConnection(invite.InvitedByUserId, invite.InvitedByOccupantId, async db => { bool occupantInvited = false; OccupantInviteResponse existingOccupant = GetFirebaseUserByEmail(invite.Email); if (existingOccupant != null) { this.logger.Information($"Creating Occupant from invite: {invite.ToString()}"); OccupantInsertRequest createOccupant = new OccupantInsertRequest { InviteAccepted = false, UserId = existingOccupant.Uid, DisplayName = existingOccupant.DisplayName, EnteredBy = invite.InvitedByUserId, InvitedByOccupantId = invite.InvitedByOccupantId }; this.logger.Information($"Creating Occupant: {createOccupant.ToString()}"); OccupantResponse newOccupant = await this.InsertOccupantQuery(db, createOccupant); this.logger.Information($"Created Occupant: {newOccupant.ToString()}"); NewsFeedInsertRequest householdInviteNewsItem = new NewsFeedInsertRequest { EnteredBy = invite.InvitedByUserId, OccupantId = invite.InvitedByOccupantId, Headline = "Invited to a new household", SubHeadline = "Congrats", Story = "You have been invited to a new household! Go to households to accept the invite.", Author = invite.InvitedByUserId, Recipient = newOccupant.UserId, }; this.logger.Information($"Creating News Feed Invite: {invite.ToString()}"); await newsFeedsRepository.InsertNewsFeedQuery(db, householdInviteNewsItem); occupantInvited = true; } else { // TODO: Improve functionality here! this.logger.Error("Existing occupant: {existingOccupant}, not found for email {invite}", existingOccupant, invite.Email); throw new Exception($"The email address {invite.Email} must sign up to myHouse first"); } return occupantInvited; })); }