コード例 #1
0
 public ActionResult Create()
 {
     var model = new RegisterViewModel
     {
         GendersList = new SelectList(_autogearRepo.GenderListItems(), "Value", "Text"),
         Areas = new MultiSelectList(_instructorRepo.GetAreasList(), "Value", "Text"),
         Status = true
     };
     return View(model);
 }
コード例 #2
0
 public async Task<ActionResult> Create(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
         var result = await _userManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             //Sending Email
              EmailAPI emp = new EmailAPI();
             var emails = new List<string> {model.Email};
             var subJect = "Account Creation";
             //Add role instructor to created user
             // Fetch role
             var role = await _roleManager.FindByNameAsync("Instructor");
             if (role != null)
             {
                  _userManager.AddToRole(user.Id, role.Name);
             }
             model.LastInstructor = _instructorRepo.GetLatestInstructorId() + 1;
             string[] addressInfo = model.SuburbName.Split(',');
             var suburb = _postalRepo.GetSuburb(addressInfo[0]);
             model.PostalCode = addressInfo[2];
             if (suburb != null)
             {
                 model.SuburbId = suburb.SuburbId;
             }
             model.InstructorId = user.Id;
             model.CreatedUser = User.Identity.GetUserId();
            _instructorRepo.SaveInstructor(model);
             //await _signInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
             return RedirectToAction("Index");
         }
         AddErrors(result);
     }
     return View(model);
 }
コード例 #3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email,FirstName = model.FirstName, LastName = model.LastName };
                var result = await _userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //Add role instructor to created user
                    // Fetch role
                    var role = await _roleManager.FindByNameAsync("Instructor");
                    if (role != null)
                    {
                       await _userManager.AddToRoleAsync(user.Id, role.Id);
                    }
                    // Create Instructor account
                    
                    //await _signInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #4
0
        public void SaveInstructor(RegisterViewModel model)
        {

            // Save Address
            var instructorAddress = new Address
            {
                Address1 = model.AddressLine1,
                AddressLine2 = model.AddressLine2,
                Phone = model.Phone,
                Mobile = model.Mobile,
                PostCode = Convert.ToInt32(model.PostalCode),
                CreatedDate = DateTime.Now,
                CreatedBy = model.CreatedUser,
            };
            if (model.SuburbId != 0)
                instructorAddress.SuburbID = model.SuburbId;
            DataContext.Addresses.Add(instructorAddress);
            SaveInDatabase();
            //  _instructorRepo.
            // Create Instructor account
            var instructor = new Instructor
            {
                Created_Date = DateTime.Now,
                InstructorId = model.InstructorId,
                Created_By = model.CreatedUser,
                InstructorNumber = "INS-" + model.LastInstructor,
                Email = model.Email,
                FirstName = model.FirstName,
                LastName = model.LastName,
                Gender = model.Gender.ToString(),
                Mobile = model.Mobile,
                Phone = model.Phone,
                AddressId = instructorAddress.AddressId,
                Status = model.Status,
                Areas = model.AreaIds
            };
            DataContext.Instructors.Add(instructor);
            SaveInDatabase();
            foreach (var iarea in model.AreaNames.Split(','))
            {
                // Instructor Area
                var instructorArea = new InstructorArea
                {
                    InstructorID = instructor.InstructorId,
                    AreaId = Convert.ToInt32(iarea)
                };
                DataContext.InstructorAreas.Add(instructorArea);
                SaveInDatabase();
            }
          
        }