Exemple #1
0
        public ActionResult Create(CreateUserViewModel createUserViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_iUserMaster.CheckEmailIdExists(createUserViewModel.EmailId))
                    {
                        TempData["MessageCreateUsersErrors"] = "EmailId Already Exists";
                    }
                    else if (_iUserMaster.CheckMobileNoExists(createUserViewModel.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }
                    else if (_iUserMaster.CheckUsernameExists(createUserViewModel.UserName))
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }
                    else
                    {
                        createUserViewModel.FirstName = UppercaseFirst(createUserViewModel.FirstName);
                        createUserViewModel.LastName  = UppercaseFirst(createUserViewModel.LastName);
                        var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel);
                        usermaster.Status     = true;
                        usermaster.CreateDate = DateTime.Now;
                        usermaster.UserId     = 0;
                        usermaster.CreatedBy  = Convert.ToInt32(_sessionHandler.UserId);
                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(createUserViewModel.Password, salt);

                        var userId = _iUserMaster.AddUser(usermaster, saltedpassword, salt, createUserViewModel.RoleId);
                        if (userId != -1)
                        {
                            TempData["MessageCreateUsers"] = "User Created Successfully";
                        }

                        return(RedirectToAction("Create", "CreateUsers"));
                    }

                    createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent();
                    return(View("Create", createUserViewModel));
                }
                else
                {
                    createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent();
                    return(View("Create", createUserViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #2
0
        public ActionResult Create(CreateNewUserViewModel createUserViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_iUserMaster.CheckEmailIdExists(createUserViewModel.EmailId))
                    {
                        TempData["MessageCreateUsersErrors"] = "EmailId Already Exists";
                    }
                    else if (_iUserMaster.CheckMobileNoExists(createUserViewModel.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }
                    else
                    {
                        string     username   = GenerateUserName(createUserViewModel);
                        Usermaster usermaster = new Usermaster();
                        usermaster.Status     = true;
                        usermaster.CreateDate = DateTime.Now;
                        usermaster.UserId     = 0;
                        usermaster.FirstName  = createUserViewModel.FirstName;
                        usermaster.LastName   = createUserViewModel.LastName;
                        usermaster.EmailId    = createUserViewModel.EmailId;
                        usermaster.MobileNo   = createUserViewModel.MobileNo;
                        usermaster.UserName   = username;
                        usermaster.CreatedBy  = Convert.ToInt32(_sessionHandler.UserId);
                        usermaster.Gender     = createUserViewModel.Gender;
                        var salt     = GenerateRandomNumbers.RandomNumbers(20);
                        var password = GeneratePassword(createUserViewModel, salt);
                        var userId   = _iUserMaster.AddUser(usermaster, password, salt, Convert.ToInt16(StatusMain.Roles.User));
                        if (userId != -1)
                        {
                            TempData["MessageCreateUsers"] = $"User Created Successfully Username :- {usermaster.UserName}";
                        }
                        return(RedirectToAction("Create", "CreateNewUser"));
                    }

                    return(View("Create", createUserViewModel));
                }
                else
                {
                    return(View("Create", createUserViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
        public ActionResult Edit(EditAgentViewModel editAgentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isUser = _iUserMaster.CheckUserIdExists(editAgentViewModel.UserId);
                    if (isUser)
                    {
                        var createUserViewModel = _iUserMaster.EditUserbyUserId(editAgentViewModel.UserId);

                        if (createUserViewModel.EmailId != editAgentViewModel.EmailId)
                        {
                            if (_iUserMaster.CheckEmailIdExists(editAgentViewModel.EmailId))
                            {
                                ModelState.AddModelError("", "EmailId already exists");
                                return(View(editAgentViewModel));
                            }
                        }

                        if (createUserViewModel.MobileNo != editAgentViewModel.MobileNo)
                        {
                            if (_iUserMaster.CheckMobileNoExists(editAgentViewModel.MobileNo))
                            {
                                ModelState.AddModelError("", "MobileNo already exists");
                                return(View(editAgentViewModel));
                            }
                        }

                        var result = _iUserMaster.UpdateAgentDetails(editAgentViewModel);
                        TempData["MessageUpdateAgent"]    = "Agent Details Updated Successfully";
                        editAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                        return(View(editAgentViewModel));
                    }
                    else
                    {
                        editAgentViewModel.ListofCategory    = _category.GetAllActiveSelectListItemCategory();
                        TempData["MessageCreateUsersErrors"] = "Agent Details doesn't exist";
                        return(View(editAgentViewModel));
                    }
                }
                else
                {
                    editAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Edit", editAgentViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #4
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;
            }
        }