Ejemplo n.º 1
0
        public async Task <IActionResult> Register(Registration model)
        {
            if (ModelState.IsValid)
            {
                IdentityUser user = new IdentityUser()
                {
                    Email    = model.Email,
                    UserName = model.Email
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var person = new Person();

                    person.Email     = model.Email;
                    person.FirstName = model.FirstName;
                    person.LastName  = model.LastName;
                    person.Password  = model.Password;
                    person.Dob       = model.DOB;

                    _db.Person.Add(person);
                    _db.SaveChanges();

                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(String.Empty, error.Description);
                    }
                }
            }

            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Enroll(Enroll model)
        {
            if (ModelState.IsValid)
            {
                var  user          = _db.Person.Where(p => p.Email == User.Identity.Name).Single();
                bool studentExists = 0 < _db.Students.Where(s => s.PersonId == user.PersonId).Count();

                if (!studentExists)
                {
                    var student = new Students();
                    student.PersonId = user.PersonId;

                    _db.Students.Add(student);
                    _db.SaveChanges();
                }

                var insertedStudent = _db.Students.Where(s => s.PersonId == user.PersonId).Single();
                if (!studentExists)
                {
                    var studentguardian = new StudentGuardians();
                    studentguardian.StudentId    = insertedStudent.StudentId;
                    studentguardian.ContactPhone = model.GuardianPhone;
                    studentguardian.Email        = model.GuardianEmail;
                    studentguardian.FirstName    = model.GuardianFirstname;
                    studentguardian.LastName     = model.GuardianLastname;

                    _db.StudentGuardians.Add(studentguardian);
                }



                var enrollment = new Enrollment();

                enrollment.StudentId    = insertedStudent.StudentId;
                enrollment.InstrumentId = model.instrumentID;
                enrollment.LessonLevel  = model.LessonLevel;

                _db.Enrollment.Add(enrollment);


                if (model.instrumentHire)
                {
                    var hire = new InstrumentHire();

                    hire.StudentId    = insertedStudent.StudentId;
                    hire.InstrumentId = model.instrumentID;

                    _db.InstrumentHire.Add(hire);
                }

                if (!studentExists)
                {
                    if (model.LessonLevel < 4)
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 0;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                    else if (model.LessonLevel > 6)
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 2;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                    else
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 1;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                }

                _db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }