public async Task <IActionResult> Execute([FromRoute] int id, [FromBody] ResearchCalculatedForm rates) { if (rates == null) { return(BadRequest(new ApiError("400", "Null model", $"Не заданы вычисленные параметры"))); } try { return(Ok(await _db.ExecuteResearchAsync(id, rates))); } catch (Exception ex) { return(BadRequest(new ApiError(ex))); } }
public async Task <Research> ExecuteResearchAsync(int id, ResearchCalculatedForm rates) { var task = await GetResearchAsync(id); if (task.AccuracyRates?.Length > 0 || task.EfficiencyRates?.Length > 0) { await RemoveRatesForAsync(id); } var items = rates.AccuracyRates.Concat(rates.EfficiencyRates); await CreateRatesForAsync(id, items); task.AccuracyRates = rates.AccuracyRates; task.EfficiencyRates = rates.EfficiencyRates; task.ExecutedAt = DateTime.Now; task.Status = ResearchStatus.EXECUTED; _db.Researches.Update(task); await _db.SaveChangesAsync(); return(task); }