Exemplo n.º 1
0
        public ActionResult Create()
        {
            CreateEditStudentViewModel vm = new CreateEditStudentViewModel
            {
                Student           = new Student(),
                CompetencyHeaders = competenciesHeadersRepository.AllIncluding(a => a.Competencies).ToList()
            };

            return(View(vm));
        }
Exemplo n.º 2
0
        private ActionResult SaveStudent(int?id, CreateEditStudentViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View(formData));
            }
            var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user        = new ApplicationUser {
                UserName = formData.Email, Email = formData.Email
            };
            var result  = userManager.Create(user, formData.Password);
            var userId  = user.Id;
            var student = Mapper.Map <Student>(formData);

            if (!id.HasValue)
            {
                var singleStudent = DbContext.StudentDatabase.ToList();
                if (singleStudent.Count != 0)
                {
                    if (singleStudent.Any(p => p.Email == student.Email))
                    {
                        var studentEmail = DbContext.StudentDatabase.FirstOrDefault(p => p.Email == student.Email).Email;
                        return(RedirectToAction(nameof(InstructorController.EmailError), "Instructor"));
                    }
                }
                //DbContext.Users.Add(user);
                DbContext.StudentDatabase.Add(student);
                //DbContext.Users.Add(user);
                DbContext.SaveChanges();
                if (!userManager.IsInRole(user.Id, "Student"))
                {
                    userManager.AddToRoleAsync(user.Id, "Student");
                }
                //string code = userManager.GenerateEmailConfirmationToken(user.Id);
                //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //userManager.SendEmailAsync(userId, "Notification",
                //    "Hello, You are registered as student at MITT.Your current Password is Password-1.Please change your password by clicking <a href=\"" + callbackUrl + "\"> here</a>");
            }
            else
            {
                student = DbContext.StudentDatabase.FirstOrDefault(p => p.Id == id);
                if (student == null)
                {
                    return(RedirectToAction(nameof(StudentsController.Index)));
                }
            }
            student.FirstName = formData.FirstName;
            student.LastName  = formData.LastName;
            student.Email     = formData.Email;
            DbContext.SaveChanges();
            return(RedirectToAction(nameof(StudentsController.Details), new { id = student.Id }));
        }
Exemplo n.º 3
0
        public ActionResult EditStudent(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(StudentsController.Index)));
            }
            var student = DbContext.StudentDatabase.FirstOrDefault(p => p.Id == id);

            if (student == null)
            {
                return(RedirectToAction(nameof(StudentsController.Index)));
            }

            var model = new CreateEditStudentViewModel();

            model.FirstName = student.FirstName;
            model.LastName  = student.LastName;
            model.Email     = student.Email;

            return(View(model));
        }
Exemplo n.º 4
0
 //[Authorize(Roles = "Admin")]
 public ActionResult CreateStudent(CreateEditStudentViewModel formData)
 {
     return(SaveStudent(null, formData));
 }
Exemplo n.º 5
0
 public ActionResult EditStudent(int id, CreateEditStudentViewModel formData)
 {
     return(SaveStudent(id, formData));
 }