Compare commits

...

35 Commits
main ... Ekz

Author SHA1 Message Date
Данияр Аглиуллов
310f02160b 1 раз 2024-02-02 11:10:52 +04:00
Данияр Аглиуллов
c892d14158 удален ненужный update 2023-02-28 23:19:51 +04:00
Данияр Аглиуллов
8860c632ee исправлена даунская ошибка эгова 2023-02-28 23:10:17 +04:00
Данияр Аглиуллов
f5c6383f1d Merge branch 'Lab3_Base' of http://student.git.athene.tech/d.agliullov/ISEbd-21_Agliullov.D.A._Confectionery into Lab3_Base 2023-02-28 22:55:56 +04:00
Данияр Аглиуллов
b2eb054e22 Добавлены цельная транзакция при обновлении изделия 2023-02-28 22:55:42 +04:00
Данияр Аглиуллов
6ca67882ec Добавлены цельная транзакция при обновлении изделия 2023-02-28 22:47:06 +04:00
Данияр Аглиуллов
f2ca847c6b Добавлена возможность получения списка компонент из бд вместе с изделием 2023-02-28 22:19:14 +04:00
Данияр Аглиуллов
b18e9a142d Добавлено вычисляемое поле PastryName в dbImplement 2023-02-28 22:14:49 +04:00
Данияр Аглиуллов
992ccc3f38 Merge branch 'Lab2_Base' into Lab3_Base 2023-02-28 22:01:22 +04:00
Данияр Аглиуллов
746f5be7a4 реализовано вычисляемое поле PastryName 2023-02-28 21:59:49 +04:00
Данияр Аглиуллов
1a8bfc323e Реализованы классы хранилища работающие с бд 2023-02-20 01:35:50 +04:00
Данияр Аглиуллов
4702f666e1 Создана база данных проекта 2023-02-19 22:48:53 +04:00
Данияр Аглиуллов
3b796baf01 Merge branch 'Lab1_Base' into Lab2_Base 2023-02-18 18:58:27 +04:00
Данияр Аглиуллов
cb864c0353 Исправлен подсчет стоимости заказа 2023-02-18 18:52:30 +04:00
Данияр Аглиуллов
77889d887e fix 2023-02-18 18:50:14 +04:00
Данияр Аглиуллов
a803558b09 fix 2023-02-15 04:33:40 +04:00
Данияр Аглиуллов
a83bd28099 fix 2023-02-15 04:33:07 +04:00
Данияр Аглиуллов
3a777a93df fix 2023-02-15 04:07:03 +04:00
Данияр Аглиуллов
9e8a3d4e87 Внедрена файловая реализация в программу 2023-02-15 04:03:18 +04:00
Данияр Аглиуллов
2a0c31d5c0 Реализованы интерфейсы классов хранилищ сущностей 2023-02-15 03:53:54 +04:00
Данияр Аглиуллов
e90f9d47cc Реализованы модели для хранения данных в файле 2023-02-15 03:21:09 +04:00
Данияр Аглиуллов
9d8f221930 удален пустой метод 2023-02-09 16:15:17 +04:00
a70cb1d782 fix 2023-02-07 11:02:43 +04:00
Данияр Аглиуллов
8ceb065f32 Исправлен время выполнения заказа 2023-02-06 22:05:06 +04:00
Данияр Аглиуллов
47cf1ab393 Исправлены заказы 2023-02-06 21:53:55 +04:00
Данияр Аглиуллов
4c75db2b27 Исправлено изменение изделия 2023-02-06 01:54:59 +04:00
Данияр Аглиуллов
8571a9a747 Исправлены заказы 2023-02-05 22:14:36 +04:00
Данияр Аглиуллов
241e701722 Переименованы подписи форм 2023-02-05 21:17:00 +04:00
Данияр Аглиуллов
a50cce3f83 Исправлено обновление значений изделия 2023-02-05 21:13:31 +04:00
Данияр Аглиуллов
c03c0457b0 fix 2023-02-05 20:59:43 +04:00
Данияр Аглиуллов
50364962ec исправлен FormComponents 2023-02-05 20:48:18 +04:00
Данияр Аглиуллов
9fd6e03690 изменена вызывающая форма в FormViewPastry 2023-02-05 20:18:08 +04:00
Данияр Аглиуллов
52ba150765 переименована переменная 2023-02-05 14:26:38 +04:00
Данияр Аглиуллов
bac3eb0a04 fix 2023-02-05 13:24:32 +04:00
Данияр Аглиуллов
bdd6aaa000 Реализована архитектура приложения 2023-02-03 23:25:31 +04:00
59 changed files with 2599 additions and 209 deletions

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryContracts\EkzamenContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,56 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.BusinessLogicsContracts;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace EkzamenBusinessLogic
{
public class GroupLogic : IGroupLogic
{
private readonly ILogger _logger;
private readonly IGroupStorage _orderStorage;
public GroupLogic(ILogger<GroupLogic> logger, IGroupStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool CreateGroup(GroupBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public List<GroupViewModel>? ReadList(GroupSearchModel? model)
{
_logger.LogInformation("ReadList. OrderName.Id:{ Id} ", model?.Id);
var list = (model == null) ? _orderStorage.GetFullList() :
_orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private bool CheckModel(GroupBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
return true;
}
}
}

View File

@ -0,0 +1,96 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.BusinessLogicsContracts;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace EkzamenBusinessLogic
{
public class StudentLogic : IStudentLogic
{
private readonly ILogger _logger;
private readonly IStudentStorage _componentStorage;
public StudentLogic(ILogger<StudentLogic> logger, IStudentStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<StudentViewModel>? ReadList(StudentSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id} ",
model?.CreatedDateFrom, model?.Id);
var list = (model == null) ? _componentStorage.GetFullList() :
_componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public StudentViewModel? ReadElement(StudentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}",
model.CreatedDateFrom, model.Id);
var element = _componentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(StudentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(StudentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(StudentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(StudentBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
}
}
}

View File

@ -0,0 +1,60 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;
using System.Xml.Linq;
namespace ConfectioneryFileImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,79 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using ConfectioneryFileImplement.Models;
namespace ConfectioneryFileImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataFileSingleton _source;
public ComponentStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
return _source.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return _source.Components
.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
return _source.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) &&
x.ComponentName == model.ComponentName) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
_source.Components.Add(newComponent);
_source.SaveComponents();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
var component = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
_source.SaveComponents();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
var element = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Components.Remove(element);
_source.SaveComponents();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,50 @@
using ConfectioneryFileImplement.Models;
using System.Xml.Linq;
namespace ConfectioneryFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string PastryFileName = "Pastry.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Pastry> Pastries { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SavePastries() => SaveData(Pastries, PastryFileName, "Pastries", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,96 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Enums;
using ConfectioneryDataModels.Models;
using System.Xml.Linq;
namespace ConfectioneryFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int PastryId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
PastryId = model.PastryId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Id = model.Id,
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
var dateImplement = element.Element("DateImplement")!.Value;
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
PastryId = Convert.ToInt32(element.Element("PastryId")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
PastryId = model.PastryId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
PastryName = DataFileSingleton.GetInstance().Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
PastryId = PastryId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("PastryId", PastryId),
new XElement("Count", Count),
new XElement("Sum", Sum.ToString()),
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement)
);
}
}

View File

@ -0,0 +1,76 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using ConfectioneryFileImplement.Models;
namespace ConfectioneryFileImplement
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton _source;
public OrderStorage()
{
_source = DataFileSingleton.GetInstance();
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Orders.Remove(element);
_source.SaveOrders();
return element.GetViewModel;
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = GetElement(model);
return result != null ? new() { result } : new();
}
public List<OrderViewModel> GetFullList()
{
return _source.Orders
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
_source.Orders.Add(newOrder);
_source.SaveOrders();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
_source.SaveOrders();
return order.GetViewModel;
}
}
}

View File

@ -0,0 +1,86 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;
using System.Xml.Linq;
namespace ConfectioneryFileImplement.Models
{
public class Pastry : IPastryModel
{
public int Id { get; private set; }
public string PastryName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _PastryComponents = null;
public Dictionary<int, (IComponentModel, int)> PastryComponents
{
get
{
if (_PastryComponents == null)
{
var source = DataFileSingleton.GetInstance();
_PastryComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
y.Value));
}
return _PastryComponents;
}
}
public static Pastry? Create(PastryBindingModel model)
{
if (model == null)
{
return null;
}
return new Pastry()
{
Id = model.Id,
PastryName = model.PastryName,
Price = model.Price,
Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Pastry? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Pastry()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PastryName = element.Element("PastryName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("PastryComponents")!.Elements("PastryComponent").ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(PastryBindingModel model)
{
if (model == null)
{
return;
}
PastryName = model.PastryName;
Price = model.Price;
Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_PastryComponents = null;
}
public PastryViewModel GetViewModel => new()
{
Id = Id,
PastryName = PastryName,
Price = Price,
PastryComponents = PastryComponents
};
public XElement GetXElement => new("Pastry",
new XAttribute("Id", Id),
new XElement("PastryName", PastryName),
new XElement("Price", Price.ToString()),
new XElement("PastryComponents", Components.Select(x =>
new XElement("PastryComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,85 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using ConfectioneryFileImplement.Models;
namespace ConfectioneryFileImplement
{
public class PastryStorage : IPastryStorage
{
private readonly DataFileSingleton _source;
public PastryStorage()
{
_source = DataFileSingleton.GetInstance();
}
public PastryViewModel? Delete(PastryBindingModel model)
{
var element = _source.Pastries.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Pastries.Remove(element);
_source.SavePastries();
return element.GetViewModel;
}
return null;
}
public PastryViewModel? GetElement(PastrySearchModel model)
{
if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
{
return null;
}
return _source.Pastries.FirstOrDefault
(x => (!string.IsNullOrEmpty(model.PastryName) && x.PastryName == model.PastryName) ||
(model.Id.HasValue && x.Id == model.Id)
)?.GetViewModel;
}
public List<PastryViewModel> GetFilteredList(PastrySearchModel model)
{
if (string.IsNullOrEmpty(model.PastryName))
{
return new();
}
return _source.Pastries
.Select(x => x.GetViewModel)
.Where(x => x.PastryName.Contains(model.PastryName))
.ToList();
}
public List<PastryViewModel> GetFullList()
{
return _source.Pastries
.Select(x => x.GetViewModel)
.ToList();
}
public PastryViewModel? Insert(PastryBindingModel model)
{
model.Id = _source.Pastries.Count > 0 ? _source.Pastries.Max(x => x.Id) + 1 : 1;
var newPastry = Pastry.Create(model);
if (newPastry == null)
{
return null;
}
_source.Pastries.Add(newPastry);
_source.SavePastries();
return newPastry.GetViewModel;
}
public PastryViewModel? Update(PastryBindingModel model)
{
var pastry = _source.Pastries.FirstOrDefault(x => x.Id == model.Id);
if (pastry == null)
{
return null;
}
pastry.Update(model);
_source.SavePastries();
return pastry.GetViewModel;
}
}
}

View File

@ -0,0 +1,24 @@
using EkzamenListImplement;
namespace ConfectioneryListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Student> Students { get; set; }
public List<Group> Groups { get; set; }
private DataListSingleton()
{
Students = new List<Student>();
Groups = new ();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryContracts\EkzamenContracts.csproj" />
<ProjectReference Include="..\ConfectioneryDataModels\EkzamenDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,46 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.ViewModels;
using EkzamenDataModels;
namespace EkzamenListImplement
{
public class Group : IGroupModel
{
public int Id { get; private set; }
public static Group? Create(GroupBindingModel? model)
{
if (model == null)
{
return null;
}
return new Group()
{
Name = model.Name,
Direction = model.Direction,
Created = model.Created,
Id = model.Id,
};
}
public void Update(GroupBindingModel? model)
{
if (model == null)
{
return;
}
Direction = model.Direction;
Id = model.Id;
}
public GroupViewModel GetViewModel => new()
{
Name = Name,
Direction = Direction,
Created = Created,
Id = Id,
};
public string Name { get; set; }
public string Direction { get; set; }
public DateTime Created { get; set; }
}
}

View File

@ -0,0 +1,73 @@
using ConfectioneryListImplement;
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
namespace EkzamenListImplement
{
public class GroupStorage : IGroupStorage
{
private readonly DataListSingleton _source;
public GroupStorage()
{
_source = DataListSingleton.GetInstance();
}
public GroupViewModel? Delete(GroupBindingModel model)
{
var group = _source.Groups.FirstOrDefault(x => x.Id == model.Id);
if (group != null)
{
_source.Groups.Remove(group);
}
return group?.GetViewModel;
}
public GroupViewModel? GetElement(GroupSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return _source.Groups.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public List<GroupViewModel> GetFilteredList(GroupSearchModel model)
{
var result = new List<GroupViewModel>();
if (!model.Id.HasValue)
{
return result;
}
return new() { GetElement(model) };
}
public List<GroupViewModel> GetFullList()
{
return _source.Groups.Select(x => x.GetViewModel).ToList();
}
public GroupViewModel? Insert(GroupBindingModel model)
{
model.Id = _source.Groups.Max(x => x.Id);
var newOrder = Group.Create(model);
if (newOrder == null)
{
return null;
}
_source.Groups.Add(newOrder);
return newOrder.GetViewModel;
}
public GroupViewModel? Update(GroupBindingModel model)
{
var group = _source.Groups.FirstOrDefault(x => x.Id == model.Id);
group?.Update(model);
return group?.GetViewModel;
return null;
}
}
}

View File

@ -0,0 +1,53 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.ViewModels;
using EkzamenDataModels;
namespace EkzamenListImplement
{
public class Student : IStudentModel
{
public int Id { get; private set; }
public static Student? Create(StudentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Student()
{
Id = model.Id,
fio = model.fio,
DateEnrollment = model.DateEnrollment,
GroupId = model.GroupId,
PassMark = model.PassMark,
RecordBookId = model.RecordBookId,
};
}
public void Update(StudentBindingModel? model)
{
if (model == null)
{
return;
}
fio = model.fio;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
fio = fio,
DateEnrollment = DateEnrollment,
GroupId = GroupId,
PassMark = PassMark,
RecordBookId = RecordBookId,
};
public string fio { get; set; } = string.Empty;
public int GroupId { get; set; }
public int RecordBookId { get; set; }
public int PassMark { get; set; }
public DateTime DateEnrollment { get; set; }
}
}

View File

@ -0,0 +1,64 @@
using ConfectioneryListImplement;
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
namespace EkzamenListImplement
{
public class StudentStorage : IStudentStorage
{
private readonly DataListSingleton _source = DataListSingleton.GetInstance();
public List<StudentViewModel> GetFullList()
{
return _source.Students.Select(x => x.GetViewModel).ToList();
}
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{
var result = new List<StudentViewModel>();
if (model.CreatedDateFrom is null || model.CreatedDateTo is null)
{
return result;
}
return _source.Students.Where(x => model.CreatedDateFrom <= x.DateEnrollment && x.DateEnrollment <= model.CreatedDateTo).Select(x => x.GetViewModel).ToList();
}
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return _source.Students.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public StudentViewModel? Insert(StudentBindingModel model)
{
model.Id = _source.Students.Max(x => x.Id);
var newComponent = Student.Create(model);
if (newComponent == null)
{
return null;
}
_source.Students.Add(newComponent);
return newComponent.GetViewModel;
}
public StudentViewModel? Update(StudentBindingModel model)
{
var student = _source.Students.FirstOrDefault(x => x.Id == model.Id);
if (student != null)
{
student.Update(model);
}
return student?.GetViewModel;
}
public StudentViewModel? Delete(StudentBindingModel model)
{
var student = _source.Students.FirstOrDefault(x => x.Id == model.Id);
if (student != null)
{
_source.Students.Remove(student);
}
return student?.GetViewModel;
}
}
}

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Confectionery", "Confectionery\Confectionery.csproj", "{4C293123-3570-4E76-A241-E28EB1498585}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C293123-3570-4E76-A241-E28EB1498585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78AE98CC-ADF5-4E98-A7A5-D775694833D7}
EndGlobalSection
EndGlobal

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectionaryBusinessLogic\EkzamenBusinessLogic.csproj" />
<ProjectReference Include="..\ConfectionaryListImplement\EkzamenListImplement.csproj" />
<ProjectReference Include="..\ConfectioneryContracts\EkzamenContracts.csproj" />
<ProjectReference Include="..\ConfectioneryDatabaseImplement\EkzamenDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -1,39 +0,0 @@
namespace Confectionery
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace Confectionery
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,17 +1,41 @@
namespace Confectionery
using EkzamenBusinessLogic;
using EkzamenContracts.BusinessLogicsContracts;
using EkzamenContracts.StoragesContract;
using EkzamenListImplement;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace EkzamenView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// To customize application configuration such as set high DPIsettings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IStudentStorage, StudentStorage>();
services.AddTransient<IGroupStorage, GroupStorage>();
services.AddTransient<IStudentLogic, StudentLogic>();
services.AddTransient<IGroupLogic, GroupLogic>();
}
}
}

View File

@ -0,0 +1,12 @@
using EkzamenDataModels;
namespace EkzamenContracts.BindingModels
{
public class GroupBindingModel : IGroupModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Direction { get; set; }
public DateTime Created { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using EkzamenDataModels;
namespace EkzamenContracts.BindingModels
{
public class StudentBindingModel : IStudentModel
{
public string fio { get; set; }
public int GroupId { get; set; }
public int RecordBookId { get; set; }
public int PassMark { get; set; }
public DateTime DateEnrollment { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.ViewModels;
namespace EkzamenContracts.BusinessLogicsContracts
{
public interface IGroupLogic
{
List<GroupViewModel>? ReadList(GroupSearchModel? model);
bool CreateGroup(GroupBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.ViewModels;
namespace EkzamenContracts.BusinessLogicsContracts
{
public interface IStudentLogic
{
List<StudentViewModel>? ReadList(StudentSearchModel? model);
StudentViewModel? ReadElement(StudentSearchModel model);
bool Create(StudentBindingModel model);
bool Update(StudentBindingModel model);
bool Delete(StudentBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryDataModels\EkzamenDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
namespace EkzamenContracts.SearchModels
{
public class GroupSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace EkzamenContracts.SearchModels
{
public class StudentSearchModel
{
public int? Id { get; set; }
public DateTime? CreatedDateFrom { get; set; }
public DateTime? CreatedDateTo { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.ViewModels;
namespace EkzamenContracts.StoragesContract
{
public interface IGroupStorage
{
List<GroupViewModel> GetFullList();
List<GroupViewModel> GetFilteredList(GroupSearchModel model);
GroupViewModel? GetElement(GroupSearchModel model);
GroupViewModel? Insert(GroupBindingModel model);
GroupViewModel? Update(GroupBindingModel model);
GroupViewModel? Delete(GroupBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.ViewModels;
namespace EkzamenContracts.StoragesContract
{
public interface IStudentStorage
{
List<StudentViewModel> GetFullList();
List<StudentViewModel> GetFilteredList(StudentSearchModel model);
StudentViewModel? GetElement(StudentSearchModel model);
StudentViewModel? Insert(StudentBindingModel model);
StudentViewModel? Update(StudentBindingModel model);
StudentViewModel? Delete(StudentBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using System.ComponentModel;
using EkzamenDataModels;
namespace EkzamenContracts.ViewModels
{
public class GroupViewModel : IGroupModel
{
public int Id { get; set; }
[DisplayName("Название группы")]
public string Name { get; set; }
[DisplayName("Направление")]
public string Direction { get; set; }
[DisplayName("Дата создания")]
public DateTime Created { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel;
using EkzamenDataModels;
namespace EkzamenContracts.ViewModels
{
public class StudentViewModel : IStudentModel
{
public int Id { get; set; }
[DisplayName("ФИО")]
public string fio { get; set; }
public int GroupId { get; set; }
[DisplayName("Зачетная книжка")]
public int RecordBookId { get; set; }
[DisplayName("Проходной балл")]
public int PassMark { get; set; }
[DisplayName("Дата поступления")]
public DateTime DateEnrollment { get; set; }
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,11 @@

namespace EkzamenDataModels
{
public interface IGroupModel : IId
{
string Name { get; set; }
string Direction { get; set; }
DateTime Created { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace EkzamenDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,13 @@
namespace EkzamenDataModels
{
public interface IStudentModel : IId
{
string fio { get; }
int GroupId { get; }
int RecordBookId { get; }
int PassMark { get; }
DateTime DateEnrollment { get; }
}
}

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
namespace EkzamenDatabaseImplement
{
public class ConfectioneryDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Перед работой необходимо установить SQL Express
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"
Server = localhost\SQLEXPRESS;
Initial Catalog = EkzamenDatabaseFull;
Integrated Security = True;
MultipleActiveResultSets = True;
TrustServerCertificate = True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Student> Students { set; get; }
public virtual DbSet<Group> Groups { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryContracts\EkzamenContracts.csproj" />
<ProjectReference Include="..\ConfectioneryDataModels\EkzamenDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,53 @@
using System.ComponentModel.DataAnnotations;
using EkzamenContracts.BindingModels;
using EkzamenContracts.ViewModels;
using EkzamenDataModels;
namespace EkzamenDatabaseImplement
{
public class Group : IGroupModel
{
public int Id { get; private set; }
public static Group? Create(GroupBindingModel? model)
{
if (model == null)
{
return null;
}
return new Group()
{
Name = model.Name,
Direction = model.Direction,
Created = model.Created,
Id = model.Id,
};
}
public void Update(GroupBindingModel? model)
{
if (model == null)
{
return;
}
Direction = model.Direction;
Id = model.Id;
}
public GroupViewModel GetViewModel =>
new()
{
Name = Name,
Direction = Direction,
Created = Created,
Id = Id,
};
[Required]
public string Name { get; set; }
[Required]
public string Direction { get; set; }
public DateTime Created { get; set; }
public List<Student> Students { get; set; }
}
}

View File

@ -0,0 +1,73 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
namespace EkzamenDatabaseImplement
{
public class GroupStorage : IGroupStorage
{
public GroupViewModel? Delete(GroupBindingModel model)
{
using var context = new ConfectioneryDatabase();
var element = context.Groups.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Groups.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public GroupViewModel? GetElement(GroupSearchModel model)
{
using var context = new ConfectioneryDatabase();
if (!model.Id.HasValue)
{
return null;
}
return context.Groups.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<GroupViewModel> GetFilteredList(GroupSearchModel model)
{
var result = GetElement(model);
return result != null ? new() { result } : new();
}
public List<GroupViewModel> GetFullList()
{
using var context = new ConfectioneryDatabase();
return context.Groups
.Select(x => x.GetViewModel)
.ToList();
}
public GroupViewModel? Insert(GroupBindingModel model)
{
var newOrder = Group.Create(model);
if (newOrder == null)
{
return null;
}
using var context = new ConfectioneryDatabase();
context.Groups.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public GroupViewModel? Update(GroupBindingModel model)
{
using var context = new ConfectioneryDatabase();
var order = context.Groups.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
}
}

View File

@ -0,0 +1,262 @@
// <auto-generated />
using System;
using ConfectioneryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ConfectioneryDatabaseImplement.Migrations
{
[DbContext(typeof(ConfectioneryDatabase))]
[Migration("20230228200344_create_shop")]
partial class create_shop
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("PastryId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("PastryId");
b.ToTable("Orders");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PastryName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Pastries");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PastryId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PastryId");
b.ToTable("PastryComponents");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<int>("MaxCountPastries")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("PastryId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PastryId");
b.ToTable("Shops");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.ShopPastry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PastryId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PastryId");
b.HasIndex("ShopId");
b.ToTable("ShopPastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Orders")
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component")
.WithMany("PastryComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Components")
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Pastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", null)
.WithMany("Shops")
.HasForeignKey("PastryId");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.ShopPastry", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany()
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Shop", "Shop")
.WithMany("ShopPastry")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pastry");
b.Navigation("Shop");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{
b.Navigation("PastryComponents");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.Navigation("ShopPastry");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,89 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ConfectioneryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class create_shop : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
MaxCountPastries = table.Column<int>(type: "int", nullable: false),
DateOpening = table.Column<DateTime>(type: "datetime2", nullable: false),
PastryId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
table.ForeignKey(
name: "FK_Shops_Pastries_PastryId",
column: x => x.PastryId,
principalTable: "Pastries",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ShopPastry",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PastryId = table.Column<int>(type: "int", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShopPastry", x => x.Id);
table.ForeignKey(
name: "FK_ShopPastry_Pastries_PastryId",
column: x => x.PastryId,
principalTable: "Pastries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ShopPastry_Shops_ShopId",
column: x => x.ShopId,
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ShopPastry_PastryId",
table: "ShopPastry",
column: "PastryId");
migrationBuilder.CreateIndex(
name: "IX_ShopPastry_ShopId",
table: "ShopPastry",
column: "ShopId");
migrationBuilder.CreateIndex(
name: "IX_Shops_PastryId",
table: "Shops",
column: "PastryId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ShopPastry");
migrationBuilder.DropTable(
name: "Shops");
}
}
}

View File

@ -0,0 +1,262 @@
// <auto-generated />
using System;
using ConfectioneryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ConfectioneryDatabaseImplement.Migrations
{
[DbContext(typeof(ConfectioneryDatabase))]
[Migration("20230228204422_create_shop1")]
partial class create_shop1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("PastryId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("PastryId");
b.ToTable("Orders");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PastryName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Pastries");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PastryId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PastryId");
b.ToTable("PastryComponents");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<int>("MaxCountPastries")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("PastryId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PastryId");
b.ToTable("Shops");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.ShopPastry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PastryId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PastryId");
b.HasIndex("ShopId");
b.ToTable("ShopPastries");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Orders")
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component")
.WithMany("PastryComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Components")
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Pastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", null)
.WithMany("Shops")
.HasForeignKey("PastryId");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.ShopPastry", b =>
{
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany()
.HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Shop", "Shop")
.WithMany("ShopPastries")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pastry");
b.Navigation("Shop");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{
b.Navigation("PastryComponents");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Shop", b =>
{
b.Navigation("ShopPastries");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,112 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ConfectioneryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class create_shop1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ShopPastry_Pastries_PastryId",
table: "ShopPastry");
migrationBuilder.DropForeignKey(
name: "FK_ShopPastry_Shops_ShopId",
table: "ShopPastry");
migrationBuilder.DropPrimaryKey(
name: "PK_ShopPastry",
table: "ShopPastry");
migrationBuilder.RenameTable(
name: "ShopPastry",
newName: "ShopPastries");
migrationBuilder.RenameIndex(
name: "IX_ShopPastry_ShopId",
table: "ShopPastries",
newName: "IX_ShopPastries_ShopId");
migrationBuilder.RenameIndex(
name: "IX_ShopPastry_PastryId",
table: "ShopPastries",
newName: "IX_ShopPastries_PastryId");
migrationBuilder.AddPrimaryKey(
name: "PK_ShopPastries",
table: "ShopPastries",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_ShopPastries_Pastries_PastryId",
table: "ShopPastries",
column: "PastryId",
principalTable: "Pastries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_ShopPastries_Shops_ShopId",
table: "ShopPastries",
column: "ShopId",
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ShopPastries_Pastries_PastryId",
table: "ShopPastries");
migrationBuilder.DropForeignKey(
name: "FK_ShopPastries_Shops_ShopId",
table: "ShopPastries");
migrationBuilder.DropPrimaryKey(
name: "PK_ShopPastries",
table: "ShopPastries");
migrationBuilder.RenameTable(
name: "ShopPastries",
newName: "ShopPastry");
migrationBuilder.RenameIndex(
name: "IX_ShopPastries_ShopId",
table: "ShopPastry",
newName: "IX_ShopPastry_ShopId");
migrationBuilder.RenameIndex(
name: "IX_ShopPastries_PastryId",
table: "ShopPastry",
newName: "IX_ShopPastry_PastryId");
migrationBuilder.AddPrimaryKey(
name: "PK_ShopPastry",
table: "ShopPastry",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_ShopPastry_Pastries_PastryId",
table: "ShopPastry",
column: "PastryId",
principalTable: "Pastries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_ShopPastry_Shops_ShopId",
table: "ShopPastry",
column: "ShopId",
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -0,0 +1,101 @@
// <auto-generated />
using System;
using EkzamenDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EkzamenDatabaseImplement.Migrations
{
[DbContext(typeof(ConfectioneryDatabase))]
[Migration("20240202070935_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("EkzamenDatabaseImplement.Group", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("Direction")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateEnrollment")
.HasColumnType("datetime2");
b.Property<int>("GroupId")
.HasColumnType("int");
b.Property<int>("PassMark")
.HasColumnType("int");
b.Property<int>("RecordBookId")
.HasColumnType("int");
b.Property<string>("fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Student", b =>
{
b.HasOne("EkzamenDatabaseImplement.Group", "Group")
.WithMany("Students")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Group", b =>
{
b.Navigation("Students");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EkzamenDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Direction = table.Column<string>(type: "nvarchar(max)", nullable: false),
Created = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
fio = table.Column<string>(type: "nvarchar(max)", nullable: false),
GroupId = table.Column<int>(type: "int", nullable: false),
RecordBookId = table.Column<int>(type: "int", nullable: false),
PassMark = table.Column<int>(type: "int", nullable: false),
DateEnrollment = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
table.ForeignKey(
name: "FK_Students_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Students_GroupId",
table: "Students",
column: "GroupId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "Groups");
}
}
}

View File

@ -0,0 +1,98 @@
// <auto-generated />
using System;
using EkzamenDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EkzamenDatabaseImplement.Migrations
{
[DbContext(typeof(ConfectioneryDatabase))]
partial class ConfectioneryDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("EkzamenDatabaseImplement.Group", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("Direction")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateEnrollment")
.HasColumnType("datetime2");
b.Property<int>("GroupId")
.HasColumnType("int");
b.Property<int>("PassMark")
.HasColumnType("int");
b.Property<int>("RecordBookId")
.HasColumnType("int");
b.Property<string>("fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Student", b =>
{
b.HasOne("EkzamenDatabaseImplement.Group", "Group")
.WithMany("Students")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("EkzamenDatabaseImplement.Group", b =>
{
b.Navigation("Students");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,57 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.RegularExpressions;
using EkzamenContracts.BindingModels;
using EkzamenContracts.ViewModels;
using EkzamenDataModels;
namespace EkzamenDatabaseImplement
{
public class Student : IStudentModel
{
public int Id { get; private set; }
public static Student? Create(StudentBindingModel model)
{
if (model == null)
{
return null;
}
return new Student()
{
Id = model.Id,
fio = model.fio,
DateEnrollment = model.DateEnrollment,
GroupId = model.GroupId,
PassMark = model.PassMark,
RecordBookId = model.RecordBookId,
};
}
public void Update(StudentBindingModel model)
{
if (model == null)
{
return;
}
fio = model.fio;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
fio = fio,
DateEnrollment = DateEnrollment,
GroupId = GroupId,
PassMark = PassMark,
RecordBookId = RecordBookId,
};
public string fio { get; set; }
public int GroupId { get; set; }
public int RecordBookId { get; set; }
public int PassMark { get; set; }
public DateTime DateEnrollment { get; set; }
public Group Group { get; set; }
}
}

View File

@ -0,0 +1,77 @@
using EkzamenContracts.BindingModels;
using EkzamenContracts.SearchModels;
using EkzamenContracts.StoragesContract;
using EkzamenContracts.ViewModels;
namespace EkzamenDatabaseImplement
{
public class StudentStorage : IStudentStorage
{
public List<StudentViewModel> GetFullList()
{
using var context = new ConfectioneryDatabase();
return context.Students
.Select(x => x.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{
if (model.CreatedDateFrom is null || model.CreatedDateTo is null)
{
return new();
}
using var context = new ConfectioneryDatabase();
return context.Students
.Where(x => model.CreatedDateFrom <= x.DateEnrollment && x.DateEnrollment <= model.CreatedDateTo)
.Select(x => x.GetViewModel)
.ToList();
}
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new ConfectioneryDatabase();
return context.Students
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public StudentViewModel? Insert(StudentBindingModel model)
{
var newComponent = Student.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new ConfectioneryDatabase();
context.Students.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public StudentViewModel? Update(StudentBindingModel model)
{
using var context = new ConfectioneryDatabase();
var component = context.Students.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public StudentViewModel? Delete(StudentBindingModel model)
{
using var context = new ConfectioneryDatabase();
var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Students.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

55
Ekzamen.sln Normal file
View File

@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenView", "Confectionery\EkzamenView.csproj", "{4C293123-3570-4E76-A241-E28EB1498585}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenDataModels", "ConfectioneryDataModels\EkzamenDataModels.csproj", "{C5FCA6F0-A6D0-47CB-B507-4A6EAA89E645}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenContracts", "ConfectioneryContracts\EkzamenContracts.csproj", "{28EC043D-88E8-48DA-B5E8-2DE5659EB1BD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenBusinessLogic", "ConfectionaryBusinessLogic\EkzamenBusinessLogic.csproj", "{82EF78A8-98EC-490A-8D66-66909E5431E2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenListImplement", "ConfectionaryListImplement\EkzamenListImplement.csproj", "{0A7B118B-9B7C-4796-9846-66026159723E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EkzamenDatabaseImplement", "ConfectioneryDatabaseImplement\EkzamenDatabaseImplement.csproj", "{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C293123-3570-4E76-A241-E28EB1498585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C293123-3570-4E76-A241-E28EB1498585}.Release|Any CPU.Build.0 = Release|Any CPU
{C5FCA6F0-A6D0-47CB-B507-4A6EAA89E645}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5FCA6F0-A6D0-47CB-B507-4A6EAA89E645}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5FCA6F0-A6D0-47CB-B507-4A6EAA89E645}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5FCA6F0-A6D0-47CB-B507-4A6EAA89E645}.Release|Any CPU.Build.0 = Release|Any CPU
{28EC043D-88E8-48DA-B5E8-2DE5659EB1BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28EC043D-88E8-48DA-B5E8-2DE5659EB1BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28EC043D-88E8-48DA-B5E8-2DE5659EB1BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28EC043D-88E8-48DA-B5E8-2DE5659EB1BD}.Release|Any CPU.Build.0 = Release|Any CPU
{82EF78A8-98EC-490A-8D66-66909E5431E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82EF78A8-98EC-490A-8D66-66909E5431E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82EF78A8-98EC-490A-8D66-66909E5431E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82EF78A8-98EC-490A-8D66-66909E5431E2}.Release|Any CPU.Build.0 = Release|Any CPU
{0A7B118B-9B7C-4796-9846-66026159723E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A7B118B-9B7C-4796-9846-66026159723E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A7B118B-9B7C-4796-9846-66026159723E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A7B118B-9B7C-4796-9846-66026159723E}.Release|Any CPU.Build.0 = Release|Any CPU
{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78AE98CC-ADF5-4E98-A7A5-D775694833D7}
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.