80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.TaskSubject;
|
|
using AccountManagement.Domain.TaskSubjectAgg;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
|
|
|
namespace AccountManagement.Application;
|
|
|
|
public class TaskSubjectApplication : ITaskSubjectApplication
|
|
{
|
|
private readonly ITaskSubjectRepository _taskSubjectRepository;
|
|
|
|
public TaskSubjectApplication(ITaskSubjectRepository taskSubjectRepository)
|
|
{
|
|
_taskSubjectRepository = taskSubjectRepository;
|
|
}
|
|
|
|
public OperationResult Create(string subject)
|
|
{
|
|
var operation = new OperationResult();
|
|
try
|
|
{
|
|
if (subject.Length > 100)
|
|
{
|
|
return operation.Failed("عنوان نمیتواند بیشتر از 100 کاراکتر باشد");
|
|
}
|
|
|
|
var taskSubject = new TaskSubject(subject);
|
|
_taskSubjectRepository.Create(taskSubject);
|
|
_taskSubjectRepository.SaveChanges();
|
|
return operation.Succcedded(taskSubject.id);
|
|
}
|
|
catch
|
|
{
|
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
|
}
|
|
}
|
|
|
|
public OperationResult Edit(TaskSubjectViewModel command)
|
|
{
|
|
var operation = new OperationResult();
|
|
try
|
|
{
|
|
if (command.Subject.Length > 100)
|
|
{
|
|
return operation.Failed("عنوان نمیتواند بیشتر از 100 کاراکتر باشد");
|
|
}
|
|
|
|
var taskSubject = _taskSubjectRepository.Get(command.Id);
|
|
taskSubject.Edit(command.Subject);
|
|
_taskSubjectRepository.SaveChanges();
|
|
return operation.Succcedded(taskSubject.id);
|
|
}
|
|
catch
|
|
{
|
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
|
}
|
|
|
|
}
|
|
|
|
public OperationResult Delete(long id)
|
|
{
|
|
var operation = new OperationResult();
|
|
try
|
|
{
|
|
_taskSubjectRepository.Remove(id);
|
|
return operation.Succcedded();
|
|
}
|
|
catch
|
|
{
|
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
|
}
|
|
}
|
|
|
|
public List<TaskSubjectViewModel> GetAll(string search)
|
|
{
|
|
return _taskSubjectRepository.GetAll(search);
|
|
}
|
|
} |