public async System.Threading.Tasks.Task <ActionResult> RegisterOrganizer(Models.Organizer.CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Data.DataDbContext context = new Data.DataDbContext();

                var user = new Data.Identity.ApplicationUser {
                    UserName  = model.registerViewModel.Email,
                    Email     = model.registerViewModel.Email, FirstName = model.registerViewModel.FirstName, LastName = model.registerViewModel.SurName,
                    EGenderId = model.registerViewModel.EGenderId, BirthDate = model.registerViewModel.BirthDate, LockoutEnabled = false
                };

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

                if (result.Succeeded)
                {
                    await UserManager.SetLockoutEnabledAsync(user.Id, false);

                    await UserManager.AddToRoleAsync(user.Id, "Organizer");

                    var organizer = new Data.Models.Organizer()
                    {
                        Name        = model.organizerViewModel.Name,
                        Description = model.organizerViewModel.Description
                    };
                    var usr = new Code.Repository.ApplicationUserRepository().GetById(user.Id);
                    organizer.Organizers.Add(usr);


                    new Code.Repository.OrganizerRepository().Create(organizer, true);

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

                    Code.MailTools.SmtpPipe.Instance.SendWelcomeEmail(user);
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }
            return(View("/Views/Organizer/Register.cshtml", model));
        }
Beispiel #2
0
 public ValuesController(Data.DataDbContext db)
 {
     _db = db;
 }