public async Task <ServiceResponse <GetBreedingRecordDto> > CreateBreedingRecordCharacteristic(CreateBreedingRecordCharacteristicDto newBreedingRecordCharacteristic) { ServiceResponse <GetBreedingRecordDto> serviceResponse = new ServiceResponse <GetBreedingRecordDto>(); try { BreedingRecord record = await _context.BreedingRecords .Include(br => br.BreedingRecordCharacteristics).ThenInclude(br => br.Characteristic) .FirstOrDefaultAsync(br => br.Id == newBreedingRecordCharacteristic.BreedingRecordId && br.User.Id == GetUserId()); if (record == null) { serviceResponse.Success = false; serviceResponse.Message = "BreedingRecord not found."; return(serviceResponse); } Characteristic characteristic = await _context.Characteristics .FirstOrDefaultAsync(c => c.Id == newBreedingRecordCharacteristic.CharacteristicId); if (characteristic == null) { serviceResponse.Success = false; serviceResponse.Message = "Characteristic not found."; return(serviceResponse); } BreedingRecordCharacteristic breedingRecordCharacteristic = new BreedingRecordCharacteristic { BreedingRecord = record, Characteristic = characteristic }; await _context.BreedingRecordCharacteristics.AddAsync(breedingRecordCharacteristic); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetBreedingRecordDto>(record); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> CreateBreedingRecord(CreateBreedingRecordCharacteristicDto newBreedingRecordCharacteristic) { return(Ok(await _breedingRecordCharacteristicService.CreateBreedingRecordCharacteristic(newBreedingRecordCharacteristic))); }