Esempio n. 1
0
        public async Task<ActionResult> Create(CreateModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = new AppUser {FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, Email = model.Email };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    AddErrorsFromResult(result);
                }
            }
            return View(model);
        }
Esempio n. 2
0
        public async Task<ActionResult> Create(CreateModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = new AppUser
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    UserName = model.UserName,
                    Email = model.Email,
                    Address = model.Address,
                    Zip = model.Zip,
                    City = model.City.ToString(),
                    Country = "Danmark",
                    Avatar = model.Avatar,
                    Gender = model.Gender.ToString(),
                    Biography = model.Biography,
                    Birthday = model.Birthday,
                    PrimaryLanguage = model.PrimaryLanguage.ToString(),
                    CreatedAt = DateTime.Now
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {


                    var addedToRole = await UserManager.AddToRoleAsync(user.Id, model.Role);
                    return RedirectToAction("Index");
                }
                else
                {
                    AddErrorsFromResult(result);
                }
            }
            ViewBag.Role = new SelectList(db.Roles, "Name", "Name");

            return View(model);
        }