public ActionResult Save(UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.err = "error";
                return(View("SignUp", userModel));
            }


            var IsExist = userRepo.CheckUserIsExistOrNot(userModel.EmailID);

            if (IsExist)
            {
                ModelState.AddModelError("Exist", "Email is Already Exists.");
                return(View("SignUp", userModel));
            }
            var roleId     = userRepo.GetRolesByName("member");
            var createuser = new User
            {
                RoleID          = roleId,
                FirstName       = userModel.FirstName,
                LastName        = userModel.LastName,
                EmailID         = userModel.EmailID,
                IsEmailVerified = false,
                Password        = userModel.Password,
                CreatedDate     = DateTime.Now,
                ModifiedDate    = DateTime.Now,
                IsActive        = true
            };

            userModel.Id = userRepo.AddUser(createuser);

            var    verifyUrl         = "/Account/EmailVerify/" + userModel.Id;
            var    link              = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);
            var    fromEmail         = new MailAddress("*****@*****.**", "NoteMarketPlace");
            var    toEmail           = new MailAddress(userModel.EmailID);
            var    fromEmailPassword = "******";
            string sub  = "Note Marketplace - Email Verification";
            string body = "Hello  " + userModel.FirstName + "<br/><br/>" +
                          "Thank you for signing up with us. Please click on below link to verify " +
                          "your email address and to do login. <br/><br/>" +
                          "<a href='" + link + "'>" + link + "</a><br/><br/>" +
                          "Regards, <br/>" +
                          "Notes MarketPlace";

            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromEmail.Address, fromEmailPassword)
            };

            using (var message = new MailMessage(fromEmail, toEmail)
            {
                Subject = sub,
                Body = body,
                IsBodyHtml = true
            })

                smtp.Send(message);


            ViewBag.msg = "success";

            ModelState.Clear();

            return(View("SignUp"));
        }
Exemplo n.º 2
0
        public ActionResult SaveAdmin(AddAdministratorViewModel admin)
        {
            int id = (int)Session["super admin"];

            if (!ModelState.IsValid)
            {
                admin.Countries = _context.GetCountries();
                return(View("AddAdministrator", admin));
            }
            var adminInDb = _context.GetAdmin(admin.AddAdmin.Id);

            if (adminInDb == null)
            {
                var IsExist = _context.CheckUserIsExistOrNot(admin.AddAdmin.Email);
                if (IsExist)
                {
                    ModelState.AddModelError("Exist", "Email is Already Exists.");
                    admin.Countries = _context.GetCountries();
                    return(View("AddAdministrator", admin));
                }
                User addAdmin = new User
                {
                    RoleID          = _context.GetRolesByName("admin"),
                    FirstName       = admin.AddAdmin.FirstName,
                    LastName        = admin.AddAdmin.LastName,
                    EmailID         = admin.AddAdmin.Email,
                    Password        = "******",
                    IsEmailVerified = true,
                    CreatedDate     = DateTime.Now,
                    CreatedBy       = id,
                    ModifiedDate    = DateTime.Now,
                    ModifiedBy      = id,
                    IsActive        = true
                };
                int adminId = _context.AddUser(addAdmin);

                UserProfile adminDetails = new UserProfile
                {
                    UserID = adminId,
                    PhoneNumberCounrtyCode = admin.AddAdmin.CountryCodeId,
                    PhoneNumber            = admin.AddAdmin.PhoneNumber,
                    AddressLine1           = "Admin",
                    AddressLine2           = "Admin",
                    City    = "Admin",
                    State   = "Admin",
                    ZipCode = "Admin",
                    Country = "Admin",
                };
                _context.AddUserDetails(adminDetails);

                return(RedirectToAction("ManageAdministrator", "Admin"));
            }
            else
            {
                adminInDb.FirstName = admin.AddAdmin.FirstName;
                adminInDb.LastName  = admin.AddAdmin.LastName;
                adminInDb.EmailID   = admin.AddAdmin.Email;
                adminInDb.IsActive  = true;
                var adminDetails = _context.GetUserProfileDetails(adminInDb.ID);
                adminDetails.PhoneNumber            = admin.AddAdmin.PhoneNumber;
                adminDetails.PhoneNumberCounrtyCode = admin.AddAdmin.CountryCodeId;

                _context.UpdateUp();

                return(RedirectToAction("ManageAdministrator", "Admin"));
            }
        }