Beispiel #1
0
        public async Task <ActionResult> Register(RegisterViewModel userInfo)
        {
            if (ModelState.IsValid)
            {
                var identityUser = new MyIdentityUser
                {
                    Email    = userInfo.Email,
                    UserName = userInfo.Email
                };
                var creationResult = await userManager.CreateAsync(identityUser, userInfo.Password);

                // User Created
                if (creationResult.Succeeded)
                {
                    var userId = identityUser.Id;
                    creationResult = userManager.AddToRole(userId, "Trainee");

                    // Role Assigned
                    if (creationResult.Succeeded)
                    {
                        // Save to Trainee Table
                        var savedTrainee = traineeService.Create(new Trainee
                        {
                            Email         = userInfo.Email,
                            Name          = userInfo.Name,
                            Is_Active     = true,
                            Creation_Date = DateTime.Now
                        });

                        if (savedTrainee == null)
                        {
                            userInfo.Message = "An Error while creating your account!";
                            return(View(userInfo));
                        }
                        return(RedirectToAction("Index", "Default"));
                    }
                }

                var message = creationResult.Errors.FirstOrDefault();

                userInfo.Message = message;
                return(View(userInfo));
            }

            return(View(userInfo));
        }
        public ActionResult <Trainee> Create(Trainee trainee)
        {
            _traineeService.Create(trainee);

            return(CreatedAtRoute("GetTrainee", new { id = trainee.Id.ToString() }, trainee));
        }