ProjectLib/ProjectLibrary/Repositores/Implementations/TicketExtensionsRepository.cs

48 lines
1.6 KiB
C#
Raw Normal View History

2024-11-12 23:13:20 +04:00
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class TicketExtensionsRepository : ITicketExtensionsRepository
{
private readonly List<TicketExtensions> _ticketExtensions = new List<TicketExtensions>();
public void CreateTicketExtension(TicketExtensions ticketExtension)
{
_ticketExtensions.Add(ticketExtension);
}
public void DeleteTicketExtension(int id)
{
var ticketExtension = _ticketExtensions.FirstOrDefault(t => t.ExtensionID == id);
if (ticketExtension != null)
{
_ticketExtensions.Remove(ticketExtension);
}
}
public TicketExtensions ReadTicketExtensionById(int id)
{
return _ticketExtensions.FirstOrDefault(t => t.ExtensionID == id) ?? TicketExtensions.CreateEntity(0, id, DateTime.Now, DateTime.Now);
}
public IEnumerable<TicketExtensions> ReadTicketExtensions()
{
return _ticketExtensions;
}
public void UpdateTicketExtension(TicketExtensions ticketExtension)
{
var existingTicketExtension = _ticketExtensions.FirstOrDefault(t => t.ExtensionID == ticketExtension.ExtensionID);
if (existingTicketExtension != null)
{
_ticketExtensions.Remove(existingTicketExtension);
_ticketExtensions.Add(ticketExtension);
}
}
}
}