Example #1
0
        public async Task <ActionResult> Save(GradeFormViewModel form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    GradeDto grade = (form.IsNew)
                        ? new GradeDto()
                        : await _gradeRepository.GetGradeById(form.Id.Value);

                    grade.Name = form.Name;

                    if (form.IsNew)
                    {
                        await _gradeRepository.PostGrade(grade);
                    }
                    else
                    {
                        await _gradeRepository.PutGrade(grade.Id.Value, grade);
                    }

                    AddPageAlerts(ViewHelpers.PageAlertType.Success, "Your changes have been saved succesfully.");

                    return(RedirectToAction("Index"));
                }
                catch (BadRequestException bre)
                {
                    AddErrorsFromAdycHttpExceptionToModelState(bre, ModelState);
                }
            }

            // Add properties to layout
            AddPageHeader(form.Title, "");

            AddBreadcrumb("Grades", Url.Action("Index", "Grades", new { area = "Admin" }));
            AddBreadcrumb(form.Title, "");

            return(View("GradeForm", form));
        }