Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor (Repository): Move repository methods into RepositoryClass (…
…out of Server) (SRP). - Resolve TaskQueue as singleton. - (minor) Optimizing usings.
- Loading branch information
Showing
23 changed files
with
149 additions
and
153 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
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
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
5 changes: 2 additions & 3 deletions
5
Rnwood.Smtp4dev/IMessagesRepository.cs → Rnwood.Smtp4dev/Data/IMessagesRepository.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
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,61 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Rnwood.Smtp4dev.DbModel; | ||
using Rnwood.Smtp4dev.Hubs; | ||
using Rnwood.Smtp4dev.Server; | ||
|
||
namespace Rnwood.Smtp4dev.Data | ||
{ | ||
public class MessagesRepository : IMessagesRepository | ||
{ | ||
private readonly ITaskQueue taskQueue; | ||
private readonly NotificationsHub notificationsHub; | ||
private readonly Smtp4devDbContext dbContext; | ||
|
||
public MessagesRepository(ITaskQueue taskQueue, NotificationsHub notificationsHub, Smtp4devDbContext dbContext) | ||
{ | ||
this.taskQueue = taskQueue; | ||
this.notificationsHub = notificationsHub; | ||
this.dbContext = dbContext; | ||
} | ||
|
||
public Task MarkMessageRead(Guid id) | ||
{ | ||
return taskQueue.QueueTask(() => | ||
{ | ||
var message = dbContext.Messages.FindAsync(id).Result; | ||
if (message?.IsUnread != true) return; | ||
message.IsUnread = false; | ||
dbContext.SaveChanges(); | ||
notificationsHub.OnMessagesChanged().Wait(); | ||
}, true); | ||
} | ||
|
||
public IQueryable<Message> GetMessages(bool unTracked = true) | ||
{ | ||
return unTracked ? dbContext.Messages.AsNoTracking() : dbContext.Messages; | ||
} | ||
|
||
public Task DeleteMessage(Guid id) | ||
{ | ||
return taskQueue.QueueTask(() => | ||
{ | ||
dbContext.Messages.RemoveRange(dbContext.Messages.Where(m => m.Id == id)); | ||
dbContext.SaveChanges(); | ||
notificationsHub.OnMessagesChanged().Wait(); | ||
}, true); | ||
} | ||
|
||
public Task DeleteAllMessages() | ||
{ | ||
return taskQueue.QueueTask(() => | ||
{ | ||
dbContext.Messages.RemoveRange(dbContext.Messages); | ||
dbContext.SaveChanges(); | ||
notificationsHub.OnMessagesChanged().Wait(); | ||
}, true); | ||
} | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
Rnwood.Smtp4dev/DbModel/Smtp4devDbContext.cs → Rnwood.Smtp4dev/Data/Smtp4devDbContext.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
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
1 change: 1 addition & 0 deletions
1
Rnwood.Smtp4dev/Migrations/20181020095712_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
Rnwood.Smtp4dev/Migrations/20181021072518_AddSessionToMessageReln.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.