ViewModel for the School class
Exemplo n.º 1
0
        public ActionResult Edit(string id, School school)
        {
            var schoolToEdit = _schoolRepository.GetNullableById(id);

            if (schoolToEdit == null)
            {
                return(RedirectToAction("Index"));
            }

            Mapper.Map(school, schoolToEdit);
            schoolToEdit.SetId(id);

            schoolToEdit.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _schoolRepository.EnsurePersistent(schoolToEdit);

                Message = "School Edited Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = SchoolViewModel.Create(Repository);
                viewModel.School = school;

                return(View(viewModel));
            }
        }
Exemplo n.º 2
0
        public static SchoolViewModel Create(IRepository repository)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new SchoolViewModel {
                School = new School()
            };

            return(viewModel);
        }
Exemplo n.º 3
0
        //
        // GET: /School/Edit/5
        public ActionResult Edit(string id)
        {
            var school = _schoolRepository.GetNullableById(id);

            if (school == null)
            {
                return(RedirectToAction("Index"));
            }

            var viewModel = SchoolViewModel.Create(Repository);

            viewModel.School = school;

            return(View(viewModel));
        }
Exemplo n.º 4
0
        //
        // GET: /School/Details/5
        public ActionResult Details(string id)
        {
            var school = _schoolRepository.GetNullableById(id);

            if (school == null)
            {
                return(RedirectToAction("Index"));
            }

            var unitsForSchool = _unitRepository.Queryable.Where(x => x.School.Id == id).ToList();

            var model = SchoolViewModel.Create(Repository);

            model.School = school;
            model.Units  = unitsForSchool;

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Create(School school)
        {
            var schoolToCreate = new School();

            Mapper.Map(school, schoolToCreate);

            schoolToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _schoolRepository.EnsurePersistent(schoolToCreate);

                Message = "School Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = SchoolViewModel.Create(Repository);
                viewModel.School = school;

                return(View(viewModel));
            }
        }
Exemplo n.º 6
0
        public static SchoolViewModel Create(IRepository repository)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new SchoolViewModel {School = new School()};

            return viewModel;
        }
Exemplo n.º 7
0
        //
        // GET: /School/Create
        public ActionResult Create()
        {
            var viewModel = SchoolViewModel.Create(Repository);

            return(View(viewModel));
        }