namespace MyOffice.Services.Account; using MyOffice.Core; using MyOffice.Data.Models.Accounts; using MyOffice.Services.Account.Domain; public partial class AccountService { public List GetAllCategories(Guid userId) { var categories = _accountCategoryRepository.GetAll(userId); return _mapper.Map>(categories); } public Exec GetCategory(Guid userId, Guid id) { var result = new Exec(GeneralExecStatus.success); var category = _accountCategoryRepository.Get(userId, id); if (category == null) { return result.Set(GeneralExecStatus.not_found); } return result.Set(_mapper.Map(category)); } public Exec CategoryAdd(Guid userId, AccountCategoryDto input) { if (input == null) throw new ArgumentNullException(nameof(input)); var result = new Exec(GeneralExecStatus.success); var category = new AccountCategory { Id = Guid.NewGuid(), UserId = userId, Name = input.Name, }; if (!_accountCategoryRepository.Add(category)) { return result.Set(GeneralExecStatus.failure); } return result.Set(_mapper.Map(category)); } public Exec CategoryUpdate(Guid userId, Guid id, AccountCategoryDto input) { if (input == null) throw new ArgumentNullException(nameof(input)); var result = new Exec(GeneralExecStatus.success); var exists = _accountCategoryRepository.Get(userId, id); if (exists == null) { return result.Set(GeneralExecStatus.not_found); } exists.Name = input.Name; if (!_accountCategoryRepository.Update(exists)) { return result.Set(GeneralExecStatus.failure); } return result.Set(_mapper.Map(exists)); } public Exec CategoryRemove(Guid userId, Guid id) { var result = new Exec(AccountCategoryRemoveResult.success); var exists = _accountCategoryRepository.Get(userId, id); if (exists == null) { return result.Set(AccountCategoryRemoveResult.not_found); } if (exists.Accounts?.Any() == true) { return result.Set(AccountCategoryRemoveResult.accounts_exists); } if (!_accountCategoryRepository.Remove(exists)) { return result.Set(AccountCategoryRemoveResult.failure); } return result.Set(_mapper.Map(exists)); } public Exec, GeneralExecStatus> AccountCategoryRemove(Guid userId, Guid accountId, Guid categoryId) { var result = new Exec, GeneralExecStatus>(GeneralExecStatus.success); var categories = _accountAccountCategoryRepository.Get(userId, accountId, categoryId); if (categories.Count == 0) { return result.Set(GeneralExecStatus.not_found); } foreach (var category in categories) { _accountAccountCategoryRepository.Remove(category); } return result.Set(_mapper.Map>(categories)); } }