ViewModel for the Instructor class
Esempio n. 1
0
        public ActionResult Edit(Guid id, Instructor instructor)
        {
            var instructorToEdit = RepositoryFactory.InstructorRepository.GetNullableById(id);

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

            instructor.Identifier = instructorToEdit.Identifier; //Don't allow chaning the identifier
            TransferValues(instructor, instructorToEdit);

            if (ModelState.IsValid)
            {
                RepositoryFactory.InstructorRepository.EnsurePersistent(instructorToEdit);

                Message = "Instructor Edited Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = InstructorViewModel.Create(Repository);
                viewModel.Instructor = instructor;

                return(View(viewModel));
            }
        }
Esempio n. 2
0
        public ActionResult Create(Instructor instructor)
        {
            if (RepositoryFactory.InstructorRepository.Queryable.Any(i => i.Identifier == instructor.Identifier))
            {
                Message =
                    string.Format(
                        "Instructor could not be created because an instructor with the identifier {0} already exists",
                        instructor.Identifier);
                return(RedirectToAction("Index"));
            }

            var instructorToCreate = new Instructor();

            TransferValues(instructor, instructorToCreate);

            if (ModelState.IsValid)
            {
                //if the instructor doesn't exist as a user account, create them an account and profile
                var existingUser =
                    RepositoryFactory.UserRepository.Queryable.SingleOrDefault(
                        x => x.Identifier == instructorToCreate.Identifier);

                if (existingUser == null)
                {
                    var profile = new Profile
                    {
                        FirstName = instructorToCreate.FirstName,
                        LastName  = instructorToCreate.LastName,
                        Email     = instructorToCreate.Identifier,
                        ImageUrl  = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"]
                    };

                    var user = new User {
                        Identifier = instructorToCreate.Identifier
                    };
                    user.AssociateProfile(profile);
                    user.Roles.Add(RepositoryFactory.RoleRepository.GetById(RoleNames.Instructor));
                    existingUser = user;
                    RepositoryFactory.UserRepository.EnsurePersistent(user);
                }

                instructorToCreate.User = existingUser;
                RepositoryFactory.InstructorRepository.EnsurePersistent(instructorToCreate);

                Message = "Instructor Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = InstructorViewModel.Create(Repository);
                viewModel.Instructor = instructor;

                return(View(viewModel));
            }
        }
Esempio n. 3
0
        public static InstructorViewModel Create(IRepository repository)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new InstructorViewModel {
                Instructor = new Instructor()
            };

            return(viewModel);
        }
Esempio n. 4
0
        //
        // GET: /Admin/Instructor/Edit/5
        public ActionResult Edit(Guid id)
        {
            var instructor = RepositoryFactory.InstructorRepository.GetNullableById(id);

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

            var viewModel = InstructorViewModel.Create(Repository);

            viewModel.Instructor = instructor;

            return(View(viewModel));
        }
Esempio n. 5
0
        //
        // GET: /Admin/Instructor/Create
        public ActionResult Create()
        {
            var viewModel = InstructorViewModel.Create(Repository);

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

            var viewModel = new InstructorViewModel {Instructor = new Instructor()};

            return viewModel;
        }