готовы хранилища для Работника
This commit is contained in:
parent
92c765b663
commit
0a6b99d4d0
@ -6,4 +6,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BusinessLogics\Storekeeper\" />
|
||||
<Folder Include="BusinessLogics\Worker\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -6,5 +6,7 @@ namespace HardwareShopContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ namespace HardwareShopContracts.SearchModels
|
||||
public class CommentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,7 @@ namespace HardwareShopContracts.SearchModels
|
||||
public class PurchaseSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,7 @@ namespace HardwareShopContracts.SearchModels
|
||||
public string? Login { get; set; } = string.Empty;
|
||||
|
||||
public string? Email { get; set; } = string.Empty;
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
public interface IBuildStorage
|
||||
{
|
||||
List<BuildViewModel> GetFullList();
|
||||
List<BuildViewModel> GetFilteredList(UserSearchModel model);
|
||||
List<BuildViewModel> GetFilteredList(BuildSearchModel model);
|
||||
BuildViewModel? GetElement(BuildSearchModel model);
|
||||
BuildViewModel? Insert(BuildBindingModel model);
|
||||
BuildViewModel? Update(BuildBindingModel model);
|
||||
|
@ -22,7 +22,7 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BuildViewModel> GetFilteredList(UserSearchModel model)
|
||||
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
@ -34,7 +34,7 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.Id)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
@ -1,6 +1,9 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
@ -8,32 +11,82 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
public List<CommentViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model.BuildId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.Where(x => x.BuildId == model.BuildId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CommentViewModel? GetElement(CommentSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CommentViewModel? Insert(CommentBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
var newComment = Comment.Create(model);
|
||||
if (newComment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Comments.Add(newComment);
|
||||
context.SaveChanges();
|
||||
return newComment.GetViewModel;
|
||||
}
|
||||
|
||||
public CommentViewModel? Update(CommentBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
var comment = context.Comments.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (comment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
comment.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.FirstOrDefault(x => x.Id == comment.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CommentViewModel? Delete(CommentBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Comments
|
||||
.Include(x => x.Build)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Comments.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
@ -8,32 +12,114 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
public List<PurchaseViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Insert(PurchaseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
var newPurchase = Purchase.Create(context, model);
|
||||
if (newPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Purchases.Add(newPurchase);
|
||||
context.SaveChanges();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newPurchase.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Update(PurchaseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var purchase = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (purchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
purchase.Update(model);
|
||||
context.SaveChanges();
|
||||
purchase.UpdateGoods(context, model);
|
||||
purchase.UpdateBuilds(context, model);
|
||||
transaction.Commit();
|
||||
return purchase.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Delete(PurchaseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Purchases.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user