public async Task <ServiceResponse <List <GetBreedingRecordDto> > > CreateBreedingRecord(CreateBreedingRecordDto newBreedingRecord) { ServiceResponse <List <GetBreedingRecordDto> > serviceResponse = new ServiceResponse <List <GetBreedingRecordDto> >(); BreedingRecord record = _mapper.Map <BreedingRecord>(newBreedingRecord); record.User = await _context.Users.FirstOrDefaultAsync(u => u.Id == GetUserId()); record.Owner = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == newBreedingRecord.OwnerId); record.Breeder = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == newBreedingRecord.BreederId); record.BirthLitter = await _context.Litters.FirstOrDefaultAsync(c => c.Id == newBreedingRecord.BirthLitterId); record.Sex = newBreedingRecord.Sex == 1 ? record.Sex = Gender.Male : record.Sex = Gender.Female; await _context.BreedingRecords.AddAsync(record); await _context.SaveChangesAsync(); serviceResponse.Data = await GetAllRecords(); return(serviceResponse); }
public async Task <IActionResult> CreateBreedingRecord(CreateBreedingRecordDto newBreedingRecord) { return(Ok(await _breedingRecordService.CreateBreedingRecord(newBreedingRecord))); }