public IActionResult SaveStep(PlanStepDTO planStep) { _loggerManager.Info($"SaveStep() was requested for a step ({planStep.Step}) of a plan({planStep.PlanId})"); HttpContext.Response.StatusCode = StatusCodes.Status202Accepted; var isDefinitive = User.IsInRole(Roles.Admin); bool result = false; if (ModelState.IsValid) { if (_planRepository.GetWorkingStep(planStep.PlanId) != planStep.Step) { _loggerManager.Warn($"SaveStep's request appeared bad for step ({planStep.Step}) of a plan({planStep.PlanId})"); return(BadRequest()); } result = _planRepository.SaveStep(planStep, isDefinitive, planStep.IsSubmitted, userId: HttpContext.GetUserId()); if (result) { ModelState.Clear(); _loggerManager.Info($"Step({planStep.Step}) was successfully saved of a plan({planStep.PlanId})"); HttpContext.Response.StatusCode = StatusCodes.Status200OK; } } var newPlanStep = _planRepository.GetStep(planStep.Step, planStep.PlanId, isDefinitive, HttpContext.GetUserId()); if (!result) { _loggerManager.Warn($"SaveStep() request was invalid for a step ({planStep.Step}) of a plan({planStep.PlanId})"); newPlanStep.FilledAnswers = planStep.AnswerGroups; } return(PartialView("~/Views/Worksheet/Partials/_StepForm.cshtml", newPlanStep)); }
public IActionResult RefreshStepForm(PlanStepDTO planStep, bool?keepFilled) { _loggerManager.Info($"RefreshStepForm wa requsted for a step({planStep.Step}) of a plan({planStep.PlanId}) with option: keepFilled = {keepFilled ?? false}"); var isDefinitive = User.IsInRole(Roles.Admin); var newPlanStep = _planRepository.GetStep(planStep.Step, planStep.PlanId, isDefinitive, HttpContext.GetUserId()); if (keepFilled != null && keepFilled.Value) { newPlanStep.FilledAnswers = planStep.AnswerGroups; if (planStep.StepTaskAnswers?.Answer?.StepTaskAnswers != null) { foreach (var stepTaskAnswer in planStep.StepTaskAnswers.Answer.StepTaskAnswers.Where(x => x.Id == 0)) { newPlanStep.StepTaskAnswers.Answer.StepTaskAnswers?.Add(stepTaskAnswer); } } } _loggerManager.Info($"RefreshStepForm successfully returned form for a step({planStep.Step}) of a plan({planStep.PlanId})"); return(PartialView("~/Views/Worksheet/Partials/_StepForm.cshtml", newPlanStep)); }