public IActionResult UpdateDevPlan(int id, [FromBody] DevPlanValidationWrapper devPlan) { try { if (devPlan == null) { _logger.LogInformation("Invalid request body."); return(StatusCode(400, "Invalid request body.")); } _logger.LogInformation("Validating request body..."); if (!ModelState.IsValid) { _logger.LogInformation($"Errors in validation: {ModelState}"); return(BadRequest(ModelState)); } var updatedDevPlan = _devPlanRepository.UpdateDevPlan(id, devPlan); if (updatedDevPlan == null) { return(StatusCode(400, $"DevPlan with id {id} not found")); } return(CreatedAtRoute("GetDevPlan", new { id = updatedDevPlan.Id }, updatedDevPlan)); } catch (Exception e) { _logger.LogError($"Something went wrong: {e}"); return(StatusCode(500, "Internal Server Error")); } }
public DevPlanDTO UpdateDevPlan(int devPlanId, DevPlanValidationWrapper devPlan) { var toUpdate = _context.DevPlans.Where(d => d.Id == devPlanId).FirstOrDefault(); if (toUpdate == null) { _logger.LogInformation($"Development Plan with id {devPlanId} does not exist."); return(null); } _logger.LogInformation($"Updating development plan with id {devPlanId}..."); Mapper.Map(devPlan, toUpdate); _context.SaveChanges(); _logger.LogInformation($"Successfully updated development plan with id {devPlanId}."); return(Mapper.Map <DevPlanDTO>(toUpdate)); }