initial load
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Commands;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.EntityFramework.DTOs;
|
||||
|
||||
namespace YouTubeViewers.EntityFramework.Commands
|
||||
{
|
||||
public class CreateYouTubeViewerCommand :ICreateYouTubeViewerCommand
|
||||
{
|
||||
private readonly YouTubeViewersDbContextFactory _contextFactory;
|
||||
|
||||
public CreateYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task Execute(YouTubeViewer youTubeViewer)
|
||||
{
|
||||
using (YouTubeViewersDbContext context = _contextFactory.Create())
|
||||
{
|
||||
YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto()
|
||||
{
|
||||
Id = youTubeViewer.Id,
|
||||
Username = youTubeViewer.Username,
|
||||
IsSubscribed = youTubeViewer.IsSubscribed,
|
||||
IsMember = youTubeViewer.IsMember,
|
||||
};
|
||||
|
||||
context.YouTubeViewers.Add(youTubeViewerDto);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Commands;
|
||||
using YouTubeViewers.EntityFramework.DTOs;
|
||||
|
||||
namespace YouTubeViewers.EntityFramework.Commands
|
||||
{
|
||||
public class DeleteYouTubeViewerCommand : IDeleteYouTubeViewerCommand
|
||||
{
|
||||
private readonly YouTubeViewersDbContextFactory _contextFactory;
|
||||
|
||||
public DeleteYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task Execute(Guid id)
|
||||
{
|
||||
using (YouTubeViewersDbContext context = _contextFactory.Create())
|
||||
{
|
||||
await Task.Delay(5000);
|
||||
YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto()
|
||||
{
|
||||
Id = id,
|
||||
};
|
||||
|
||||
context.YouTubeViewers.Remove(youTubeViewerDto);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Commands;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.EntityFramework.DTOs;
|
||||
|
||||
namespace YouTubeViewers.EntityFramework.Commands
|
||||
{
|
||||
public class UpdateYouTubeViewerCommand : IUpdateYouTubeViewerCommand
|
||||
{
|
||||
private readonly YouTubeViewersDbContextFactory _contextFactory;
|
||||
|
||||
public UpdateYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task Execute(YouTubeViewer youTubeViewer)
|
||||
{
|
||||
using (YouTubeViewersDbContext context = _contextFactory.Create())
|
||||
{
|
||||
YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto()
|
||||
{
|
||||
Id = youTubeViewer.Id,
|
||||
Username = youTubeViewer.Username,
|
||||
IsSubscribed = youTubeViewer.IsSubscribed,
|
||||
IsMember = youTubeViewer.IsMember,
|
||||
};
|
||||
|
||||
context.YouTubeViewers.Update(youTubeViewerDto);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user