-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
434 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/FairPlayCombinedSln/FairPlayCombined.DataAccess/Models/FairPlayTube/UserMessage1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated> | ||
#nullable disable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
using FairPlayCombined.DataAccess.Models.dboSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayBudgetSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayDatingSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayShopSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlaySocialSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayTubeSchema; | ||
|
||
|
||
namespace FairPlayCombined.DataAccess.Models.FairPlayTubeSchema; | ||
|
||
[Table("UserMessage", Schema = "FairPlayTube")] | ||
public partial class UserMessage1 | ||
{ | ||
[Key] | ||
public long UserMessageId { get; set; } | ||
|
||
[Required] | ||
[StringLength(450)] | ||
public string FromApplicationUserId { get; set; } | ||
|
||
[Required] | ||
[StringLength(450)] | ||
public string ToApplicationUserId { get; set; } | ||
|
||
[Required] | ||
public string Message { get; set; } | ||
|
||
[Required] | ||
[StringLength(250)] | ||
public string SourceApplication { get; set; } | ||
|
||
[Required] | ||
[StringLength(100)] | ||
public string OriginatorIpaddress { get; set; } | ||
|
||
public DateTimeOffset RowCreationDateTime { get; set; } | ||
|
||
[Required] | ||
[StringLength(256)] | ||
public string RowCreationUser { get; set; } | ||
|
||
public bool ReadByDestinatary { get; set; } | ||
|
||
[ForeignKey("FromApplicationUserId")] | ||
[InverseProperty("UserMessage1FromApplicationUser")] | ||
public virtual AspNetUsers FromApplicationUser { get; set; } | ||
|
||
[ForeignKey("ToApplicationUserId")] | ||
[InverseProperty("UserMessage1ToApplicationUser")] | ||
public virtual AspNetUsers ToApplicationUser { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...layCombinedSln/FairPlayCombined.Models/FairPlayTube/Conversation/ConversationUserModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Models.FairPlayTube.Conversation | ||
{ | ||
/// <summary> | ||
/// Holds the data regarding an ApplicationUser | ||
/// </summary> | ||
public class ConversationsUserModel | ||
{ | ||
[Required] | ||
[StringLength(450)] | ||
/// <summary> | ||
/// Id of an application user | ||
/// </summary> | ||
public string? ApplicationUserId { get; set; } | ||
/// <summary> | ||
/// User's Full Name | ||
/// </summary> | ||
[Required] | ||
[StringLength(150)] | ||
public string? FullName { get; set; } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/FairPlayCombinedSln/FairPlayCombined.Models/FairPlayTube/UserMessage/UserMessageModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Models.FairPlayTube.UserMessage | ||
{ | ||
|
||
/// <summary> | ||
/// Represents the User Message entry | ||
/// </summary> | ||
public class UserMessageModel | ||
{ | ||
/// <summary> | ||
/// ApplicationUserId of the user to whom the message is sent | ||
/// </summary> | ||
public string? ToApplicationUserId { get; set; } | ||
/// <summary> | ||
/// Full Name of the To Application User | ||
/// </summary> | ||
public string? ToApplicationUserFullName { get; set; } | ||
/// <summary> | ||
/// Full Name of the From Application User | ||
/// </summary> | ||
public string? FromApplicationUserFullName { get; set; } | ||
/// <summary> | ||
/// Message to be sent | ||
/// </summary> | ||
[Required] | ||
public string? Message { get; set; } | ||
/// <summary> | ||
/// UTC DateTime the message was created | ||
/// </summary> | ||
public DateTimeOffset? RowCreationDateTime { get; set; } | ||
/// <summary> | ||
/// Indicated if the message has been read by the destinatary | ||
/// </summary> | ||
public bool ReadByDestinatary { get; set; } | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/FairPlayCombinedSln/FairPlayCombined.Services/FairPlayTube/UserMessageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using FairPlayCombined.DataAccess.Data; | ||
using FairPlayCombined.Interfaces; | ||
using FairPlayCombined.Models.FairPlayTube.Conversation; | ||
using FairPlayCombined.Models.FairPlayTube.UserMessage; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Services.FairPlayTube | ||
{ | ||
public partial class UserMessageService( | ||
IDbContextFactory<FairPlayCombinedDbContext> dbContextFactory, | ||
IUserProviderService userProviderService) : BaseService | ||
{ | ||
public async Task<ConversationsUserModel[]?> GetMyConversationsUsersAsync( | ||
CancellationToken cancellationToken) | ||
{ | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); | ||
var currentUser = await | ||
dbContext.AspNetUsers | ||
.SingleAsync(p => p.Id == | ||
userProviderService.GetCurrentUserId(), cancellationToken: cancellationToken); | ||
var receivedMessagesUsers = await dbContext.UserMessage1 | ||
.Include(p => p.FromApplicationUser) | ||
.Where(p => p.ToApplicationUserId == currentUser.Id) | ||
.Select(p => p.FromApplicationUser) | ||
.Distinct().ToListAsync(); | ||
var sentMessagesUsers = await dbContext.UserMessage1 | ||
.Include(p => p.ToApplicationUser) | ||
.Where(p => p.FromApplicationUserId == currentUser.Id) | ||
.Select(p => p.ToApplicationUser) | ||
.Distinct().ToListAsync(); | ||
var result = receivedMessagesUsers | ||
.Union(sentMessagesUsers) | ||
.Distinct() | ||
.Select(p=>new ConversationsUserModel() | ||
{ | ||
ApplicationUserId = p.Id, | ||
FullName = p.UserName | ||
}) | ||
.ToArray(); | ||
return result; | ||
} | ||
|
||
public async Task<UserMessageModel[]?> GetMyConversationsWithUserAsync(string? userId, CancellationToken cancellationToken) | ||
{ | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); | ||
var currentUser = await | ||
dbContext.AspNetUsers | ||
.SingleAsync(p => p.Id == | ||
userProviderService.GetCurrentUserId(), cancellationToken: cancellationToken); | ||
return await dbContext.UserMessage1 | ||
.Include(p => p.ToApplicationUser) | ||
.Include(p => p.FromApplicationUser) | ||
.Where(p => | ||
(p.FromApplicationUserId == currentUser.Id && | ||
p.ToApplicationUserId == userId) | ||
|| | ||
(p.FromApplicationUserId == userId && | ||
p.ToApplicationUserId == currentUser.Id) | ||
) | ||
.OrderByDescending(p => p.RowCreationDateTime) | ||
.Select(p=>new UserMessageModel() | ||
{ | ||
FromApplicationUserFullName = p.FromApplicationUser.UserName, | ||
Message = p.Message, | ||
ReadByDestinatary = p.ReadByDestinatary, | ||
RowCreationDateTime = p.RowCreationDateTime, | ||
ToApplicationUserFullName = p.ToApplicationUser.UserName, | ||
ToApplicationUserId = p.ToApplicationUserId | ||
}).ToArrayAsync(cancellationToken); | ||
} | ||
|
||
public async Task SendMessageAsync(UserMessageModel? userMessageModel, | ||
CancellationToken cancellationToken) | ||
{ | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); | ||
await dbContext.UserMessage1.AddAsync( | ||
new DataAccess.Models.FairPlayTubeSchema.UserMessage1() | ||
{ | ||
FromApplicationUserId = userProviderService.GetCurrentUserId(), | ||
ToApplicationUserId = userMessageModel!.ToApplicationUserId, | ||
Message = userMessageModel.Message, | ||
}, cancellationToken); | ||
await dbContext.SaveChangesAsync(cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/FairPlayCombinedSln/FairPlayCombinedDb/FairPlayTube/Tables/UserMessage.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE [FairPlayTube].[UserMessage] | ||
( | ||
[UserMessageId] BIGINT NOT NULL CONSTRAINT PK_UserMessage PRIMARY KEY IDENTITY, | ||
[FromApplicationUserId] NVARCHAR(450) NOT NULL CONSTRAINT FK_FromApplicationUserId_AspNetUsers FOREIGN KEY REFERENCES [dbo].[AspNetUsers]([Id]), | ||
[ToApplicationUserId] NVARCHAR(450) NOT NULL CONSTRAINT FK_ToApplicationUserId_AspNetUsers FOREIGN KEY REFERENCES [dbo].[AspNetUsers]([Id]), | ||
[Message] NVARCHAR(MAX) NOT NULL, | ||
[SourceApplication] NVARCHAR(250) NOT NULL, | ||
[OriginatorIpaddress] NVARCHAR(100) NOT NULL, | ||
[RowCreationDateTime] DATETIMEOFFSET NOT NULL, | ||
[RowCreationUser] NVARCHAR(256) NOT NULL, | ||
[ReadByDestinatary] BIT NOT NULL DEFAULT 0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.