Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    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>");
                    //Assign Role to user Here
                    await this.UserManager.AddToRoleAsync(user.Id, model.UserRoles);

                    //Ends Here


                    // Sept 15th 2019 - Create a user profile object here, if student Id present
                    // -------------------------------------------------------
                    // RegisterViewModel obj comes in with studentId
                    // -------------------------------------------------------
                    //Guid globalId = Guid.Parse(User.Identity.GetUserId());
                    Guid globalId = Guid.Parse(user.Id);
                    var  service  = new StudentProfileService(globalId);

                    // Create a new student profile

                    service.CreateProfile(new StudentProfileCreate()
                    {
                        UserId    = globalId,
                        StudentId = model.StudentId,
                        Hobby1    = "",
                        Hobby2    = "",
                        Hobby3    = ""
                    });

                    ViewBag.HasProfile = true;


                    //return RedirectToAction("Index", "User");
                    return(RedirectToAction("Index", "Club"));
                }
                ViewBag.Name = new SelectList(context.Roles.Where(u => !u.Name.Contains("Admin"))
                                              .ToList(), "Name", "Name");
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            ViewBag.Name = new SelectList(context.Roles.Where(u => !u.Name.Contains("Admin"))
                                          .ToList(), "Name", "Name");
            return(View(model));
        }
        public ActionResult Create(StudentProfileCreate model)
        {
            // Add to DB
            var service = new StudentProfileService(_userId);

            service.CreateProfile(model);
            ViewBag.HasProfile = true;
            return(RedirectToAction("Index", "Club"));
        }
Exemplo n.º 3
0
        private StudentProfileService CreateStudentProfileService(Guid userId)
        {
            var service = new StudentProfileService(userId);

            return(service);
        }
Exemplo n.º 4
0
 public StudentProfileController()
 {
     _studentService = new StudentProfileService();
 }