2015-01-19 18:37:48 +11:00
|
|
|
using System.Collections.Generic;
|
2015-01-22 19:19:21 +11:00
|
|
|
using System.Linq;
|
2015-01-19 18:37:48 +11:00
|
|
|
using System.Linq.Expressions;
|
2015-07-23 20:04:40 +02:00
|
|
|
using Umbraco.Core.Events;
|
2015-01-19 18:37:48 +11:00
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
using Umbraco.Core.Persistence.Querying;
|
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Services
|
|
|
|
|
{
|
|
|
|
|
public class TaskService : RepositoryService, ITaskService
|
|
|
|
|
{
|
2015-07-23 20:04:40 +02:00
|
|
|
public TaskService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
|
|
|
|
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
2015-01-19 18:37:48 +11:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 19:19:21 +11:00
|
|
|
public TaskType GetTaskTypeByAlias(string taskTypeAlias)
|
|
|
|
|
{
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
2015-02-22 21:36:02 +01:00
|
|
|
return repo.GetByQuery(repo.Query.Where(type => type.Alias == taskTypeAlias)).FirstOrDefault();
|
2015-01-22 19:19:21 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskType GetTaskTypeById(int id)
|
|
|
|
|
{
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repo.Get(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(TaskType taskType)
|
|
|
|
|
{
|
|
|
|
|
var uow = UowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repo.AddOrUpdate(taskType);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(TaskType taskTypeEntity)
|
|
|
|
|
{
|
|
|
|
|
var uow = UowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repo.Delete(taskTypeEntity);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TaskType> GetAllTaskTypes()
|
|
|
|
|
{
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repo.GetAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 18:37:48 +11:00
|
|
|
|
|
|
|
|
public IEnumerable<Task> GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
|
|
|
|
|
{
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repo.GetTasks(itemId, assignedUser, ownerUser, taskTypeAlias);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 19:03:28 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
public void Save(Task task)
|
|
|
|
|
{
|
|
|
|
|
var uow = UowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repo.AddOrUpdate(task);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-22 19:19:21 +11:00
|
|
|
|
|
|
|
|
public void Delete(Task task)
|
|
|
|
|
{
|
|
|
|
|
var uow = UowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repo.Delete(task);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task GetTaskById(int id)
|
|
|
|
|
{
|
|
|
|
|
using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repo.Get(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-19 18:37:48 +11:00
|
|
|
}
|
|
|
|
|
}
|