From 6a89dbdbc681e48a4193397d04ae11d073796eab Mon Sep 17 00:00:00 2001
From: FLARJ <122087628+FLARJ@users.noreply.github.com>
Date: Fri, 7 Apr 2023 16:27:51 +0400
Subject: [PATCH] fix
---
.../FurnitureFactoryDataBaseImplement.csproj | 4 -
.../Implements/HeadsetStorage.cs | 140 ++++++++++++++++++
.../Models/IManagerModel.cs | 1 -
3 files changed, 140 insertions(+), 5 deletions(-)
create mode 100644 FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/HeadsetStorage.cs
diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplement/FurnitureFactoryDataBaseImplement.csproj b/FurnitureFactory/FurnitureFactoryDataBaseImplement/FurnitureFactoryDataBaseImplement.csproj
index 9efcd71..dbf7e6b 100644
--- a/FurnitureFactory/FurnitureFactoryDataBaseImplement/FurnitureFactoryDataBaseImplement.csproj
+++ b/FurnitureFactory/FurnitureFactoryDataBaseImplement/FurnitureFactoryDataBaseImplement.csproj
@@ -6,10 +6,6 @@
enable
-
-
-
-
diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/HeadsetStorage.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/HeadsetStorage.cs
new file mode 100644
index 0000000..e4839b1
--- /dev/null
+++ b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/HeadsetStorage.cs
@@ -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 HeadsetSalesSalons { get; }
+ int ManagerId { get; }
+ int HeadsetModuleId { get; }
+
+
+
+
+
+
+ public List 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 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;
+ }
+ }
+}
diff --git a/FurnitureFactory/FurnitureFactoryDataModels/Models/IManagerModel.cs b/FurnitureFactory/FurnitureFactoryDataModels/Models/IManagerModel.cs
index 96ec69e..54e9376 100644
--- a/FurnitureFactory/FurnitureFactoryDataModels/Models/IManagerModel.cs
+++ b/FurnitureFactory/FurnitureFactoryDataModels/Models/IManagerModel.cs
@@ -12,7 +12,6 @@ namespace FurnitureFactoryDataModels.Models
string Login { get; }
string Password { get; }
string Email { get; }
- string Role { get; }
string UserName { get; }
}
}
\ No newline at end of file