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 GetFullList() { return _source.Students.Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(StudentSearchModel model) { var result = new List(); 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; } } }