ProjectLib/ProjectLibrary/Repositores/Implementations/TicketExtensionsRepository.cs

48 lines
1.6 KiB
C#

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);
}
}
}
}