public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Type = model.Type };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    ApplicationDbContext db = new ApplicationDbContext();

                    GeneralUser generalUser = null;
                    if (user.Type == 1)
                        generalUser = new StudentUser() { Email = user.Email };
                    else generalUser = new ProviderUser() { Email = user.Email };

                    ApplicationUser savedUser = db.Users.FirstOrDefault(x => x.Id == user.Id);
                    savedUser.GeneralUser = generalUser;
                    db.Entry(savedUser).State = System.Data.Entity.EntityState.Modified;

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {

                    }

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
					if (user.Type == 1)
	                    return RedirectToAction("Index", "student");
					else
						return RedirectToAction("Index", "providers");
				}
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemple #2
0
 public void ProviderMatcher_MatchingTest()
 {
     //Arrange
     GeneralUser initiator = new StudentUser();
     //initiator.Interests = new List<>
 }