private async Task SaveStatusesAsync(Battery battery, List <Status> statuses) { foreach (var status in statuses) { status.BatteryId = battery.Id; status.OwnerId = battery.OwnerId; await _statusService.AddAsync(status); } }
public async Task<ActionResult<ReadStatusDto>> Add([FromBody] CreateStatusDto createStatusDto) { try { var addedStatus = await _statusService.AddAsync(createStatusDto); return CreatedAtAction("Add", addedStatus); } catch (TaskException ex) { return Conflict(ex.Message); } }
public async Task <ActionResult <Status> > PostAsync(StatusModel status) { try { var mapper = _mapper.Map <Status>(status); var total = await _service.AddAsync(mapper); if (total > 0) { return(new CreatedResult("", mapper)); } return(new AcceptedResult()); } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } }