Ejemplo n.º 1
0
 public DatabaseFactory()
 {
     dataContext = new airportContext();
 }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                //if (ModelState.IsValid)
                //{
                //    var user = new User
                //    {
                //        UserName = model.Email,
                //        Email = model.Email,
                //        cin = model.CIN,
                //        adress = model.Adress,
                //        firstName = model.FirstName,
                //        lastName = model.LastName,
                //        phoneNumber = model.phonenumber.ToString()
                //    };

                var user = new user
                {
                    UserName = model.UserName,
                    Email    = model.Email,
                    // user.username = model.username;
                    score     = 0,
                    lastName  = model.lastName,
                    firstName = model.firstName,
                    //user.password = model.Password;
                    //user.addressMail = model.Email;
                    DTYPE = "Customer",
                    //user.password = model.Password;
                    dateRegistration = DateTime.Now,
                    EmailConfirmed   = true,
                    sexe             = model.sexe
                };
                //user.PhoneNumber = "000000";
                user.EmailConfirmed = true;
                var    ctxx        = new airportContext();
                var    RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(ctxx));
                string name        = "Customer";

                //Create Role Customer if it does not exist
                if (!RoleManager.RoleExists(name))
                {
                    var roleresult = RoleManager.Create(new IdentityRole(name));
                }
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var            userNew = UserManager.FindById(user.Id);
                    var            manage  = UserManager.AddToRole(userNew.Id, name);
                    airportContext ctx     = new airportContext();
                    ctx.SaveChanges();

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    // 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>");

                    return(RedirectToAction("Welcome", "Welcome"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
 public UnitOfWork(IDatabaseFactory dbFactory)
 {
     this.dbFactory = dbFactory;
     dataContext    = dbFactory.DataContext;
 }