Пример #1
0
        public ActionResult Save(ScheduleEditViewModel viewModel)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (viewModel.Id.HasValue)
                    {
                        _scheduleManager.EditSchedule(viewModel.Id.Value, viewModel.ResponsibleId.Value, viewModel.StartAt.Value, viewModel.EndAt.Value);
                    }
                    else
                    {
                        _scheduleManager.AddSchedule(viewModel.ResponsibleId.Value, viewModel.StartAt.Value, viewModel.EndAt.Value);
                    }

                    return(RedirectToAction(nameof(Index)));
                }

                viewModel.People = _personManager.GetPersonList().OrderBy(p => p.Name).ToList();

                return(View(nameof(Edit), viewModel));
            } catch (Exception exc) {
                ModelState.AddModelError("", exc.Message);

                viewModel.People = _personManager.GetPersonList().OrderBy(p => p.Name).ToList();

                return(View(nameof(Edit), viewModel));
            }
        }