public async Task <PersonResponse> EditPersonAsync(EditPersonRequest request) { Person existingRecord = await _personRespository.GetAsync(request.Id); if (existingRecord == null) { throw new ArgumentException($"Entity with {request.Id} is not present"); } if (request.PictureId != null) { FAGBinary existingPicture = await _fagBinaryRespository.GetAsync(request.PictureId); if (existingPicture == null) { throw new NotFoundException($"Picture with {request.PictureId} is not present"); } } Person entity = _personMapper.Map(request); Person result = _personRespository.Update(entity); int modifiedRecords = await _personRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id); return(_personMapper.Map(result)); }
public async Task <CompanyResponse> EditCompanyAsync(EditCompanyRequest request) { Company existingRecord = await _companyRespository.GetAsync(request.Id); if (existingRecord == null) { throw new ArgumentException($"Entity with {request.Id} is not present"); } if (request.ParentId != null) { Company existingParent = await _companyRespository.GetAsync(request.ParentId); if (existingParent == null) { throw new NotFoundException($"Parent with {request.ParentId} is not present"); } } CompanyType existingCompanyType = await _companyTypeRespository.GetAsync(request.CompanyTypeId); if (existingCompanyType == null) { throw new NotFoundException($"CompanyType with {request.CompanyTypeId} is not present"); } Country existingCountry = await _countryRespository.GetAsync(request.CountryId); if (existingCountry == null) { throw new NotFoundException($"Country with {request.CountryId} is not present"); } if (request.LogoId != null) { FAGBinary existingFAGBinary = await _fagBinaryRespository.GetAsync(request.LogoId); if (existingFAGBinary == null) { throw new NotFoundException($"Logo with {request.LogoId} is not present"); } } Company entity = _companyMapper.Map(request); Company result = _companyRespository.Update(entity); int modifiedRecords = await _companyRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id); return(_companyMapper.Map(result)); }
public async Task <FAGBinaryResponse> DeleteFAGBinaryAsync(DeleteFAGBinaryRequest request) { if (request?.Id == null) { throw new ArgumentNullException(); } FAGBinary result = await _fagBinaryRespository.GetAsync(request.Id); if (result == null) { throw new ArgumentException($"Entity with {request.Id} is not present"); } _fagBinaryRespository.Update(result); int modifiedRecords = await _fagBinaryRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Logging.Events.Delete, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); return(_fagBinaryMapper.Map(result)); }