public async Task <IActionResult> UpdatePlanningAppState(int id, [FromBody] UpdatePlanningAppStateResource planningAppStateResource) { var planningAppState = await repository.GetPlanningAppState(id); var planningApp = await planningAppRepository.GetPlanningApp(planningAppState.PlanningAppId); var dueByDate = planningAppStateResource.DueByDate.ParseInputDate(); if (dueByDate != planningAppState.DueByDate) { planningAppState.UpdateCustomDueByDate(dueByDate); planningApp.updateDueByDates(); //Regenerate due by dates } //Set any fields in the PlanningApp table that have been set in the Rule List foreach (var customStateValueResource in planningAppStateResource.PlanningAppStateCustomFieldsResource) { planningAppState.getPlanningAppStateCustomField(customStateValueResource.Id).StrValue = customStateValueResource.Value; } //Store custom fields in planning state planningApp.UpdateKeyFields(planningAppStateResource.PlanningAppStateCustomFieldsResource); planningAppState.Notes = planningAppStateResource.Notes; repository.Update(planningAppState); await unitOfWork.CompleteAsync(); return(Ok()); }
public async Task <PlanningAppStateFullResource> UpdatePlanningAppState(int id, [FromBody] UpdatePlanningAppStateResource planningAppStateResource) { var planningAppState = await repository.GetPlanningAppState(id); var planningApp = await planningAppRepository.GetPlanningApp(planningAppState.PlanningAppId); var dueByDate = planningAppStateResource.DueByDate.ParseInputDate(); if (dueByDate != planningAppState.DueByDate) { PlanningAppStateService.UpdateCustomDueByDate(planningAppState, dueByDate); PlanningAppService.UpdateDueByDates(planningApp); //Updates all forward dueby dates from current position } //Set any fields in the PlanningApp table that have been set in the Rule List if (planningAppStateResource.PlanningAppStateCustomFieldsResource.Count() > 0) { foreach (var customStateValueResource in planningAppStateResource.PlanningAppStateCustomFieldsResource) { planningAppState.getPlanningAppStateCustomField(customStateValueResource.Id).StrValue = customStateValueResource.Value; } //Store custom fields in planning state planningApp.UpdateKeyFields(planningAppStateResource.PlanningAppStateCustomFieldsResource); } planningAppState.Notes = planningAppStateResource.Notes; repository.Update(planningAppState); await unitOfWork.CompleteAsync(); return(await GetPlanningAppState(id)); }