public ActionResult Registration(RegistrationView registrationView)
        {
            bool   statusRegistration  = false;
            string messageRegistration = string.Empty;

            if (ModelState.IsValid)
            {
                // Email Verification
                string userName = Membership.GetUserNameByEmail(registrationView.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry: Email already Exists");
                    return(View(registrationView));
                }

                //Save User Data
                using (TradeBulkEntities dbContext = new TradeBulkEntities())
                {
                    var user = new User()
                    {
                        Username       = registrationView.Username,
                        FirstName      = registrationView.FirstName,
                        LastName       = registrationView.LastName,
                        Email          = registrationView.Email,
                        Password       = Security.Encrypt(registrationView.Password),
                        ActivationCode = Guid.NewGuid(),
                    };

                    dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                    var RoleInfo = (from roles in dbContext.Roles select roles.RoleName).ToList <string>();
                    ViewBag.AvailableRoles = new SelectList(RoleInfo.ToList(), "Name", "Name");
                }

                //Verification Email
                VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString());
                messageRegistration = "Your account has been created successfully. ^_^";
                statusRegistration  = true;
            }
            else
            {
                messageRegistration = "Something Wrong!";
            }
            ViewBag.Message = messageRegistration;
            ViewBag.Status  = statusRegistration;

            return(View(registrationView));
        }
        public ActionResult ActivationAccount(string id)
        {
            bool statusAccount = false;

            using (TradeBulkEntities dbContext = new TradeBulkEntities())
            {
                var userAccount = dbContext.Users.Where(u => u.ActivationCode.ToString().Equals(id)).FirstOrDefault();

                if (userAccount != null)
                {
                    userAccount.IsActive = true;
                    dbContext.SaveChanges();
                    statusAccount = true;
                }
                else
                {
                    ViewBag.Message = "Something Wrong !!";
                }
            }
            ViewBag.Status = statusAccount;
            return(View());
        }
Example #3
0
 public void SaveChanges()
 {
     context.SaveChanges();
 }