public async Task <Response <int> > Handle(DeleteUnitCodeByIdCommand command, CancellationToken cancellationToken) { var unitcode = await _unitCodeRepository.GetUnitCodeByIdAsync(command.Id); if (unitcode == null) { throw new ApiException($"UnitCode Not Found."); } await _unitCodeRepository.DeleteAsync(unitcode); return(new Response <int>(unitcode.Id)); }
public static async Task SeedAsync(IUnitCodeRepositoryAsync unitCodeRepository) { // Seed Default UnitCode var defaultUnicode = new UnitCode { Id = (int)UnitCodes.ROOT_UNITCODE, Name = "Quản trị phần mềm", PhoneNumber = "033.248.7344", Address = "Thanh Trì - Hà Nội", Describe = "Quản trị phần mềm" }; var unitCode = await unitCodeRepository.GetUnitCodeByIdAsync(defaultUnicode.Id); if (unitCode == null) { await unitCodeRepository.AddAsync(defaultUnicode); } }
public async Task <Response <int> > Handle(UpdateUnitCodeCommand command, CancellationToken cancellationToken) { var unitcode = await _unitCodeRepository.GetUnitCodeByIdAsync(command.Id); if (unitcode == null) { throw new ApiException($"UnitCode Not Found."); } else { unitcode.Name = command.Name; unitcode.Parent = command.Parent; unitcode.PhoneNumber = command.PhoneNumber; unitcode.Address = command.Address; unitcode.Describe = command.Describe; unitcode.IsDelete = command.IsDelete; await _unitCodeRepository.UpdateAsync(unitcode); return(new Response <int>(unitcode.Id)); } }