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 GetFilteredList(GroupSearchModel model) { var result = new List(); if (!model.Id.HasValue) { return result; } return new() { GetElement(model) }; } public List 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; } } }