52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.TaskTitle;
|
|
using CompanyManagment.App.Contracts.TaskTitle;
|
|
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class TaskTitleRepository : RepositoryBase<long, TaskTitle>, ITaskTitleRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public TaskTitleRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public EditTaskTitle GetDetails(long id)
|
|
{
|
|
return _context.TaskTitles.Select(x => new EditTaskTitle
|
|
{
|
|
Id = x.id,
|
|
Title = x.Title
|
|
}).FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public void Remove(long id)
|
|
{
|
|
var taskTitle = Get(id);
|
|
|
|
Remove(taskTitle);
|
|
|
|
SaveChanges();
|
|
}
|
|
|
|
public List<TaskTitleViewModel> Search(TaskTitleSearchModel searchModel)
|
|
{
|
|
var query = _context.TaskTitles.Select(x => new TaskTitleViewModel
|
|
{
|
|
Id = x.id,
|
|
Title = x.Title
|
|
});
|
|
|
|
//TODO if
|
|
if (!string.IsNullOrEmpty(searchModel.Title))
|
|
{
|
|
query = query.Where(x => x.Title.Contains(searchModel.Title));
|
|
}
|
|
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
}
|
|
} |