Exemple #1
0
        public async Task <ActionResult> Register(UsermasterView usermaster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!this.IsCaptchaValid("Captcha is not valid"))
                    {
                        ModelState.AddModelError("", "Error: captcha is not valid.");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckUsernameExists(usermaster.UserName))
                    {
                        ModelState.AddModelError("", "UserName already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckEmailIdExists(usermaster.EmailId))
                    {
                        ModelState.AddModelError("", "EmailId already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckMobileNoExists(usermaster.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }

                    var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster);
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(usermaster.Password, salt);

                    var userId = _iUserMaster.AddUser(autoUsermaster, saltedpassword, salt, Convert.ToInt16(StatusMain.Roles.User));
                    if (userId != -1)
                    {
                        var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6)));
                        _verification.SendRegistrationVerificationToken(userId, emailVerficationToken);

                        SendingEmailhelper sendingEmailhelper = new SendingEmailhelper();
                        var name = string.Concat(usermaster.FirstName, usermaster.LastName);
                        await sendingEmailhelper.SendVerificationEmailasync(usermaster.EmailId, name, emailVerficationToken, "Registration", Convert.ToString(userId));

                        TempData["MessageRegistration"] = "Thank you. Your Registration has been completed successfully.";
                    }
                    else
                    {
                        TempData["ErrorRegistration"] = "Something Went Wrong While you are registering.Please try after sometime.";
                    }

                    return(RedirectToAction("Register", "Registration"));
                }
                else
                {
                    return(View("Register", usermaster));
                }
            }
            catch
            {
                throw;
            }
        }