fix
This commit is contained in:
parent
d040b5293b
commit
6a89dbdbc6
@ -6,10 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureContracts\FurnitureContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureFactoryDataModels\FurnitureFactoryDataModels.csproj" />
|
||||
|
@ -0,0 +1,140 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FurnitureFactoryDataModels.Models;
|
||||
using FurnitureContracts.BindingModels;
|
||||
using FurnitureContracts.ViewModel;
|
||||
using FurnitureContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureFactoryDataBaseImplements.Implements
|
||||
{
|
||||
public class HeadsetStorage : IHeadsetStorage
|
||||
{
|
||||
int Cost { get; }
|
||||
string Size { get; }
|
||||
public Dictionary<int, ISalesSalonsModel> HeadsetSalesSalons { get; }
|
||||
int ManagerId { get; }
|
||||
int HeadsetModuleId { get; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<HeadsetViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureDataBase();
|
||||
return context.Headsets
|
||||
.Include(x => x.SalesSalons)
|
||||
.ThenInclude(x => x.SalesSalons)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<HeadsetViewModel> GetFilteredList(HeadsetSearchModel model)
|
||||
{
|
||||
|
||||
if (!model.ManagerId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new FurnitureDataBase();
|
||||
//if (model.DateFrom.HasValue && model.DateTo.HasValue && model.StudentId.HasValue)
|
||||
//{
|
||||
// return context.Diys
|
||||
// .Include(x => x.Interests)
|
||||
// .ThenInclude(x => x.Interest)
|
||||
// .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.StudentId == model.StudentId)
|
||||
// .ToList()
|
||||
// .Select(x => x.GetViewModel)
|
||||
// .ToList();
|
||||
//}
|
||||
|
||||
return context.Headsets
|
||||
.Include(x => x.SalesSalons)
|
||||
.ThenInclude(x => x.SalesSalon)
|
||||
.Where(x => x.ManagerId == model.ManagerId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public HeadsetViewModel? GetElement(HeadsetSearchModel model)
|
||||
{
|
||||
if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.ManagerId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureDataBase();
|
||||
return context.Headsets
|
||||
.Include(x => x.SalesSalons)
|
||||
.ThenInclude(x => x.SalesSalons)
|
||||
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Size) && x.Size == model.Size) ||
|
||||
(model.Id.HasValue && x.Id == model.Id)) && x.ManagertId == model.ManagerId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public HeadsetViewModel? Insert(HeadsetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureDataBase();
|
||||
var newHeadset = Headset.Create(context, model);
|
||||
if (newHeadset == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Headsets.Add(newHeadset);
|
||||
context.SaveChanges();
|
||||
return newHeadset.GetViewModel;
|
||||
}
|
||||
|
||||
public HeadsetViewModel? Update(HeadsetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureDataBase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var headset = context.Headsets.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (headset == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
headset.Update(model);
|
||||
context.SaveChanges();
|
||||
headset.UpdateSalesSalons(context, model);
|
||||
transaction.Commit();
|
||||
return headset.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public HeadsetViewModel? Delete(HeadsetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureDataBase();
|
||||
var element = context.Headsets
|
||||
.Include(x => x.SalesSalons)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Headsets.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ namespace FurnitureFactoryDataModels.Models
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
string Email { get; }
|
||||
string Role { get; }
|
||||
string UserName { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user