/// <summary> /// Update an action plan /// </summary> /// <param name="actionPlanObj">ActionPlanUpdateModel</param> /// <returns>ActionPlanModel</returns> public async Task <ActionPlanModel> UpdateActionPlan(ActionPlanUpdateModel actionPlanObj) { ActionPlanDAO plan = await _repoActionPlans.GetItemAsync(actionPlanObj.ActionPlanId); if (plan == null) { throw new Exception($"No action plan found that matches responseid: {actionPlanObj.ActionPlanId}"); } string etag = plan.ETag; DateTime creationDate = plan.CreationDate; plan = _mapper.Map <ActionPlanDAO>(actionPlanObj); plan.ETag = etag; plan.CreationDate = creationDate; try { await _repoActionPlans.UpdateItemAsync(plan); } catch (DocumentClientException e) { //Update concurrency issue, retrying if (e.StatusCode == HttpStatusCode.PreconditionFailed) { return(await UpdateActionPlan(actionPlanObj)); } throw e; } var output = _mapper.Map <ActionPlanModel>(plan); return(output); }
public async Task <ActionPlanModel> UpdateActionPlan(ActionPlanUpdateModel actionPlanObj) { RestRequest request = await PrepareQuery("ActionPlans", Method.PUT); request.AddParameter("application/json", JsonConvert.SerializeObject(actionPlanObj), ParameterType.RequestBody); var queryResult = await _client.ExecuteTaskAsync <ActionPlanModel>(request); if (queryResult.IsSuccessful) { return(queryResult.Data); } else { _logger.LogError($"UpdateActionPlan: Error while updating an actionplan: {queryResult.StatusCode}"); } return(null); }
public async Task <IActionResult> UpdateActionPlan(ActionPlanUpdateModel actionPlanObj) { var result = await _actionPlanDataManager.UpdateActionPlan(actionPlanObj); return(Ok(result)); }