Example #1
0
        public ActionResult Register()
        {
            Common.Models.Response <List <MaritalStatus> > response = userBLL.GetMaritalStatus();
            if (response.IsSuccess)
            {
                ViewBag.MaritalStatusList = response.Result;
            }
            else
            {
                ViewBag.ScriptUp = response.Message.FirstOrDefault();
            }

            return(View());
        }
        public async Task <IActionResult> Register(AddUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                string path = string.Empty;

                if (model.PictureFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.PictureFile, "Users");
                }

                model.UserCode = _userHelper.GetUserCode(model.FirstName, model.LastName);
                UserEntity user = await _userHelper.AddUserAsync(model, path);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "This email is already used.");
                    model.UserTypes = _combosHelper.GetComboRoles();
                    return(View(model));
                }

                string myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user);

                string tokenLink = Url.Action("ConfirmEmail", "Account", new
                {
                    userid = user.Id,
                    token  = myToken
                }, protocol: HttpContext.Request.Scheme);

                Common.Models.Response response = _mailHelper.SendMail(model.Username, "Email confirmation", $"<h1>Email Confirmation</h1>" +
                                                                       $"To allow the user, " +
                                                                       $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>");
                if (response.IsSuccess)
                {
                    ViewBag.Message = "The instructions to allow your user has been sent to email.";
                    return(View(model));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }

            model.UserTypes = _combosHelper.GetComboRoles();
            model.Campaigns = _combosHelper.GetComboCampaigns();
            return(View(model));
        }