using System; using System.Collections.Generic; using _0_Framework.Application; using Company.Domain.Petition; using CompanyManagment.App.Contracts.Petition; namespace CompanyManagment.Application; public class PetitionApplication : IPetitionApplication { private readonly IPetitionRepository _petitionRepository; public PetitionApplication(IPetitionRepository petitionRepository) { _petitionRepository = petitionRepository; } public OperationResult Create(CreatePetition command) { var operation = new OperationResult(); var petitionIssuanceDate = new DateTime?(); var notificationPetitionDate = new DateTime?(); if (!string.IsNullOrWhiteSpace(command.PetitionNo) || !string.IsNullOrWhiteSpace(command.NotificationPetitionDate) || !string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) || !string.IsNullOrWhiteSpace(command.TotalPenalty)) { if (string.IsNullOrWhiteSpace(command.PetitionNo)) { return operation.Failed("لطفا شماره دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate)) { return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate)) { return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.TotalPenalty)) { return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید"); } } if (command.PetitionIssuanceDate != null) petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime(); if (command.NotificationPetitionDate != null) notificationPetitionDate = command.NotificationPetitionDate.ToGeorgianDateTime(); //TODO if //if(_BoardRepository.Exists(x=>x.Branch == command.Branch)) // operation.Failed("fail message") var petition = new Petition(command.PetitionNo, petitionIssuanceDate, notificationPetitionDate, command.TotalPenalty, command.TotalPenaltyTitles, command.Description, command.WorkHistoryDescription, command.BoardType_Id, command.File_Id); _petitionRepository.Create(petition); _petitionRepository.SaveChanges(); return operation.Succcedded(petition.id); } public OperationResult Edit(EditPetition command) { var operation = new OperationResult(); var petition = _petitionRepository.Get(command.Id); var petitionIssuanceDate = new DateTime?(); var notificationPetitionDate = new DateTime?(); if (!string.IsNullOrWhiteSpace(command.PetitionNo) || !string.IsNullOrWhiteSpace(command.NotificationPetitionDate) || !string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) || !string.IsNullOrWhiteSpace(command.TotalPenalty)) { if (string.IsNullOrWhiteSpace(command.PetitionNo)) { return operation.Failed("لطفا شماره دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate)) { return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate)) { return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید"); } if (string.IsNullOrWhiteSpace(command.TotalPenalty)) { return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید"); } } if (command.PetitionIssuanceDate != null) petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime(); if (command.NotificationPetitionDate != null) notificationPetitionDate = command.NotificationPetitionDate.ToGeorgianDateTime(); //TODO //if(_BoardRepository.Exists(x=>x.Branch == command.Branch)) // operation.Failed("fail message") petition.Edit(command.PetitionNo, petitionIssuanceDate, notificationPetitionDate, command.TotalPenalty, command.TotalPenaltyTitles, command.Description, command.WorkHistoryDescription, command.BoardType_Id, command.File_Id); _petitionRepository.SaveChanges(); return operation.Succcedded(petition.id); } public EditPetition GetDetails(long id) { return _petitionRepository.GetDetails(id); } public EditPetition GetDetails(long fileId, int boardTypeId) { return _petitionRepository.GetDetails(fileId, boardTypeId); } public List Search(PetitionSearchModel searchModel) { return _petitionRepository.Search(searchModel); } }