public async Task <IActionResult> AddOrUpdateEHorizontalMarksAsync( [FromBody] MarksForm <EHorizontalAttempt> marksForm, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(new ApiError(ModelState))); } var entry = await _entryService.GetEntryByIdAsync(marksForm.entryId, ct); if (entry == null) { return(NotFound("Entry not found")); } var evt = await _eventService.GetEventByIdAsync(marksForm.eventId, ct); if (evt.Params.EventType[0] != 'H') { return(BadRequest("Event type not horizontal")); } if (evt.Params.MeasurementType[0] != 'E') { return(BadRequest("Measurement type not English")); } await _markService.AddOrUpdateEHorizontalMarksAsync(marksForm, ct); return(Created(Url.Link(nameof(MarksController.GetMarksByEntryAsync), new { marksForm.entryId }), null)); }
public async Task <int> AddOrUpdateMHorizontalMarksAsync( MarksForm <MHorizontalAttempt> marksForm, CancellationToken ct) { var query = _context.MetricHorizontalMarks .Where(e => e.entryId == marksForm.entryId).ToArray(); _context.MetricHorizontalMarks.RemoveRange(query); foreach (MHorizontalAttempt att in marksForm.Marks) { _context.MetricHorizontalMarks .Add(new MHorizontalMarkEntity { entryId = marksForm.entryId, AttemptNum = att.AttemptNum, Meters = att.Meters, Wind = att.Wind }); } var created = await _context.SaveChangesAsync(ct); if (created < 1) { throw new InvalidOperationException ("Could not Add/Update marks"); } return(0); }
public async Task <IActionResult> AddOrUpdateVerticalMarksAsync( [FromBody] MarksForm <VerticalAttempt> marksForm, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(new ApiError(ModelState))); } var entry = await _entryService.GetEntryByIdAsync(marksForm.entryId, ct); if (entry == null) { return(NotFound("Entry not found")); } var evt = await _eventService.GetEventByIdAsync(marksForm.eventId, ct); if (evt.Params.EventType[0] != 'V') { return(BadRequest("Event type not vertical")); } await _markService.AddOrUpdateVerticalMarksAsync(marksForm, ct); return(Created("ok", null)); }