Ejemplo n.º 1
0
        public ActionResult Edit(StudentDetailsEditModel studentModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "User data has not been filled correctly. Please, re-enter");
                return(View(studentModel));
            }

            Student student = this.studentService.GetById(studentModel.Id);

            if (student == null)
            {
                ModelState.AddModelError(string.Empty, "No such user exists");
                return(View());
            }

            bool usernameUnique = this.studentService.IsUserNameUniqueOnEdit(
                student,
                studentModel.AccountDetailsEditModel.UserName);

            bool emailUnique = this.studentService.IsEmailUniqueOnEdit(
                student,
                studentModel.AccountDetailsEditModel.Email);

            if (!usernameUnique)
            {
                ModelState.AddModelError("AccountDetailsEditModel.UserName", "Duplicate usernames are not allowed.");
                return(View());
            }

            if (!emailUnique)
            {
                ModelState.AddModelError("AccountDetailsEditModel.Email", "Duplicate emails are not allowed.");
                return(View());
            }

            Mapper.Map <StudentDetailsEditModel, Student>(studentModel, student);
            Mapper.Map <AccountDetailsEditModel, ApplicationUser>(
                studentModel.AccountDetailsEditModel, student.ApplicationUser);



            this.studentService.Update(student);

            RedirectUrl redirectUrl = Session["redirectUrl"] as RedirectUrl;

            redirectUrl = redirectUrl ?? new RedirectUrl();

            if (!string.IsNullOrEmpty(redirectUrl.RedirectControllerName))
            {
                return(RedirectToAction(
                           redirectUrl.RedirectActionName,
                           redirectUrl.RedirectControllerName,
                           redirectUrl.RedirectParameters));
            }

            return(RedirectToAction("Index", "Students"));
        }
Ejemplo n.º 2
0
        public ActionResult StudentDetails(Guid id, string username)
        {
            Student     s           = this.studentService.GetByUserName(username);
            SchoolClass schoolClass = this.schoolClassService.GetById(id);


            if (schoolClass == null)
            {
                return(RedirectToAction("Index", "SchoolClasses"));
            }

            StudentDetailsEditModel studentModel =
                Mapper.Map <Student, StudentDetailsEditModel>(s);

            studentModel.AccountDetailsEditModel = Mapper.Map <ApplicationUser, AccountDetailsEditModel>(
                s.ApplicationUser);

            return(View(studentModel));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Details(string username)
        {
            if (username == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Student student = this.studentService.GetByUserName(username);

            if (student == null)
            {
                return(HttpNotFound());
            }

            StudentDetailsEditModel model = Mapper.Map <Student, StudentDetailsEditModel>(student);

            model.AccountDetailsEditModel = Mapper.Map <ApplicationUser, AccountDetailsEditModel>(
                student.ApplicationUser);

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Edit(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                ModelState.AddModelError(string.Empty, "No user has been selected");
                return(View());
            }

            Student student = this.studentService.GetByUserName(username);

            if (student == null)
            {
                ModelState.AddModelError(string.Empty, "Such a user does not exist");
                return(View());
            }

            StudentDetailsEditModel studentModel = Mapper.Map <Student, StudentDetailsEditModel>(student);

            studentModel.AccountDetailsEditModel = Mapper.Map <ApplicationUser, AccountDetailsEditModel>(
                student.ApplicationUser);

            return(View(studentModel));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(StudentDetailsEditModel studentModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "User data has not been filled correctly. Please, re-enter");
                return(View(studentModel));
            }

            Student student = this.studentService.GetById(studentModel.Id);

            if (student == null)
            {
                ModelState.AddModelError(string.Empty, "No such user exists");
                return(View());
            }

            bool usernameUnique = this.studentService.IsUserNameUniqueOnEdit(
                student,
                studentModel.AccountDetailsEditModel.UserName);

            bool emailUnique = this.studentService.IsEmailUniqueOnEdit(
                student,
                studentModel.AccountDetailsEditModel.Email);

            if (!usernameUnique)
            {
                ModelState.AddModelError("AccountDetailsEditModel.UserName", "Duplicate usernames are not allowed.");
                return(View());
            }

            if (!emailUnique)
            {
                ModelState.AddModelError("AccountDetailsEditModel.Email", "Duplicate emails are not allowed.");
                return(View());
            }

            Mapper.Map <StudentDetailsEditModel, Student>(studentModel, student);
            Mapper.Map <AccountDetailsEditModel, ApplicationUser>(
                studentModel.AccountDetailsEditModel, student.ApplicationUser);

            List <string> validImageTypes = new List <string>()
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (studentModel.AccountDetailsEditModel.ImageUpload != null &&
                !validImageTypes.Contains(studentModel.AccountDetailsEditModel.ImageUpload.ContentType))
            {
                ModelState.AddModelError("", "Please choose either a GIF, JPG or PNG image.");
                return(View(studentModel));
            }

            var uploadDirectory = GlobalConstants.StudentsProfileImagesUploadDirectory;

            studentModel.UploadProfilePhoto(uploadDirectory);

            if (studentModel.AccountDetailsEditModel.ImageUpload == null ||
                studentModel.AccountDetailsEditModel.ImageUpload.ContentLength == 0)
            {
                student.ApplicationUser.ImageUrl = GlobalConstants.DefaultProfileImageUrl;
            }
            else
            {
                student.ApplicationUser.ImageUrl = studentModel.AccountDetailsEditModel.ImageUrl;
            }

            this.studentService.Update(student);

            RedirectUrl redirectUrl = Session["redirectUrl"] as RedirectUrl;

            redirectUrl = redirectUrl ?? new RedirectUrl();

            if (!string.IsNullOrEmpty(redirectUrl.RedirectControllerName))
            {
                return(RedirectToAction(
                           redirectUrl.RedirectActionName,
                           redirectUrl.RedirectControllerName,
                           redirectUrl.RedirectParameters));
            }

            return(RedirectToAction("Index", "Students"));
        }