This commit is contained in:
FLARJ 2023-04-07 16:27:51 +04:00
parent d040b5293b
commit 6a89dbdbc6
3 changed files with 140 additions and 5 deletions

View File

@ -6,10 +6,6 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FurnitureContracts\FurnitureContracts.csproj" /> <ProjectReference Include="..\FurnitureContracts\FurnitureContracts.csproj" />
<ProjectReference Include="..\FurnitureFactoryDataModels\FurnitureFactoryDataModels.csproj" /> <ProjectReference Include="..\FurnitureFactoryDataModels\FurnitureFactoryDataModels.csproj" />

View File

@ -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;
}
}
}

View File

@ -12,7 +12,6 @@ namespace FurnitureFactoryDataModels.Models
string Login { get; } string Login { get; }
string Password { get; } string Password { get; }
string Email { get; } string Email { get; }
string Role { get; }
string UserName { get; } string UserName { get; }
} }
} }