public IHttpActionResult EditIndexPlanLocationAndNote( UpdateIndexPlanLocationAndNote updateIndexPlanLocationAndNote) { try { bool result = false; foreach (var item in updateIndexPlanLocationAndNote.PlanLocation) { var planLocation = _planService.FindPlanLocation(item.Id); planLocation.Index = item.Index; planLocation.PlanDay = item.PlanDay; result = _planService.UpdatePlanLocation(planLocation); } if (result) { foreach (var item in updateIndexPlanLocationAndNote.PlanNotes) { var planNote = _planService.FindNote(item.Id); planNote.Index = item.Index; planNote.PlanDay = item.PlanDay; result = _planService.UpdatePlanNote(planNote); } } if (result) { return(Ok()); } else { return(BadRequest()); } } catch (Exception ex) { _loggingService.Write(GetType().Name, nameof(EditIndexPlanLocationAndNote), ex); return(InternalServerError(ex)); } }
public IHttpActionResult UpdatePlan(UpdatePlanViewModels viewModels, UpdateIndexPlanLocationAndNote updateIndexPlanLocationAndNote) { try { Plan plan = _planService.Find(viewModels.Id); if (plan == null) { return(BadRequest()); } plan.StartDate = viewModels.StartDate; plan.EndDate = viewModels.EndDate; plan.Name = viewModels.Name; _planService.Update(plan); try { bool result = false; foreach (var item in updateIndexPlanLocationAndNote.PlanLocation) { var planLocation = _planService.FindPlanLocation(item.Id); planLocation.Index = item.Index; planLocation.PlanDay = item.PlanDay; result = _planService.UpdatePlanLocation(planLocation); } if (result) { foreach (var item in updateIndexPlanLocationAndNote.PlanNotes) { var planNote = _planService.FindNote(item.Id); planNote.Index = item.Index; planNote.PlanDay = item.PlanDay; result = _planService.UpdatePlanNote(planNote); } } if (result) { return(Ok()); } else { return(BadRequest()); } } catch (Exception ex) { _loggingService.Write(GetType().Name, nameof(EditIndexPlanLocationAndNote), ex); return(InternalServerError(ex)); } return(Ok()); } catch (Exception ex) { _loggingService.Write(GetType().Name, nameof(UpdatePlan), ex); return(InternalServerError(ex)); } }