public bool ActiveEmialVerification(User userObj)
        {
            User dbEntry = context.Users.Find(userObj.ID);
            if (dbEntry != null)
            {
                dbEntry.FullName = userObj.FullName;
                dbEntry.Email = userObj.Email;
                dbEntry.Password = userObj.Password;
                dbEntry.UserType = userObj.UserType;
                dbEntry.PrimaryUser = userObj.PrimaryUser;
                dbEntry.ConfirmPassword = userObj.Password;
                dbEntry.EmailVerified =true;
                dbEntry.Status = userObj.Status;
                dbEntry.LastModifiedDate = DateTime.Now;
                context.SaveChanges();

                Account acc = context.Accounts.Where(a => a.ID == dbEntry.AccountID).FirstOrDefault();
                accRepository.ActivateTrialAccount(acc);

                return true;
            }
            return false;
        }
 public User SaveUser(User userObj)
 {
     if (userObj.ID == 0)
     {
         context.Users.Add(userObj);
         context.SaveChanges();
     }
     else
     {
         User dbEntry = context.Users.Find(userObj.ID);
         if (dbEntry != null)
         {
             dbEntry.FullName = userObj.FullName;
             dbEntry.Email = userObj.Email;
             dbEntry.Password = userObj.Password;
             //dbEntry.UserType = userObj.UserType;
             dbEntry.PrimaryUser = userObj.PrimaryUser;
             dbEntry.ConfirmPassword = userObj.Password;
             //dbEntry.GUID = userObj.GUID;
             dbEntry.Status = userObj.Status;
             dbEntry.LastModifiedDate = DateTime.Now;
             dbEntry.isPasswordChange = userObj.isPasswordChange;
             context.SaveChanges();
         }
     }
     return userObj;
 }
        public ActionResult EditUser(User userObj)
        {
            if (ModelState.IsValid)
            {
                User currentUserObj = (User)Session["user"];
                Account accountObj = (Account)Session["account"];
                userObj.AccountID = currentUserObj.AccountID;

                var userExsist = CCUserRepository.Users.Where(u => u.Email == userObj.Email).Count();

                if (userObj.ID == 0 && userExsist == 0)
                {
                    //new user
                    userObj.GUID = Guid.NewGuid().ToString();
                    userObj.Password = Membership.GeneratePassword(12, 1);

                    var notifObj = new Notification()
                    {
                        Subject = "Welcome to Corporate contacts !",
                        RecipientAddress = userObj.Email,
                        //RecipientAddress = "*****@*****.**",
                        // Message = "Hello, \n\n" + currentUserObj.FullName + " has invited you to join corporate contacts.\nClick the link below to join.\n\n" + Request.Url.GetLeftPart(UriPartial.Authority) + "/signup/NewUser?guid=" + userObj.GUID + "\n\nCorporate Contacts Team"
                        //Message = "Hello, \n\n" + currentUserObj.FullName + " has invited you to join corporate contacts. \nClick the link below to join.\n\n" + Request.Url.GetLeftPart(UriPartial.Authority) + "/VerifyUserAccount/VerifyEmailAddress?GUID=" + userObj.GUID + "\n\n" +
                        //"/n/n/Corporate Contacts Team."

                       // Message = "Hello, \n\n" + currentUserObj.FullName + " has invited you to join corporate contacts. \nClick the link below to join.\n\n" + Request.Url.GetLeftPart(UriPartial.Authority) + "/VerifyUserAccount/VerifyEmailAddress?GUID=" + userObj.GUID + "\n\n . Your credentials " +
                       //" for the system are as follows. /n/n Username : "******"/n/n/ Password : "******"/n/n/Corporate Contacts Team"

                        Message = "<html><head></head><body><div><center> <table border='0' cellpadding='0' cellspacing='0' height='100%' width='100%'> <tbody><tr> <td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='600'> <tbody><tr> </tr><tr> <td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%'> <tbody><tr> <td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='600'> <tbody><tr> <td align='center' valign='top' width='600' style='padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;border-top:1px solid #cccccc;border-right:1px solid #cccccc;border-left:1px solid #cccccc;background-color:#ffffff'><img src='http://corporate-contacts.com/wp-content/uploads/2014/03/CorporateContactslogo3a2.png' style='max-width: 450px;margin-top: 20px;' alt='Dyn'></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr> <td align='center' valign='top' style='border-left:1px solid #cccccc;border-right:1px solid #cccccc;background-color:#ffffff'><table border='0' cellpadding='0' cellspacing='0' width='100%' style='background-color:#ffffff'> <tbody><tr> <td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%'> <tbody><tr> <td valign='top' style='padding-top:20px;padding-right:30px;padding-left:30px'><table align='left' border='0' cellpadding='0' cellspacing='0'> <tbody><tr> <td valign='top' style='color:#444444;font-family:Helvetica;font-size:16px;line-height:125%;text-align:left;padding-bottom:20px'><p>Dear " + userObj.FullName + "</p><p> '" + accountObj.AccountName + "' has created an account for you in Corporate Contacts, a leading online contact and appointment management software.</p><p>Shown below are the credentials to the system. But first you need Click on the link below to join Corporate Contacts.<a href='" + Request.Url.GetLeftPart(UriPartial.Authority) + "/VerifyUserAccount/VerifyEmailAddress?GUID=" + userObj.GUID + "'>Click Here</a></p><p><a style='text-decoration:underline;color:#0066cc' href='" + Request.Url.GetLeftPart(UriPartial.Authority) + "/VerifyUserAccount/VerifyEmailAddress?GUID=" + userObj.GUID + "' target='_blank'>" + Request.Url.GetLeftPart(UriPartial.Authority) + "/VerifyUserAccount/VerifyEmailAddress?GUID=" + userObj.GUID + "</a></p><p><strong>Username :</strong> " + userObj.Email + "</p><p><strong>Password:</strong> " + userObj.Password + "</p><p>If you need help, you can find it here: <a href='http://support.corporate-contacts.com'>support.corporate-contacts.com</a></p><p>Regards,<br><a style='text-decoration:underline;color:#0066cc' href='http://corporate-contacts.com/' target='_blank'>The Corporate Contacts team</a></p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr> <td align='center' valign='top' style='border-left:1px solid #cccccc;border-right:1px solid #cccccc'><table border='0' cellpadding='0' cellspacing='0' width='100%' style='background-color: #209FD1;'> <tbody><tr> <td align='center' valign='bottom'><table border='0' cellpadding='0' cellspacing='0' width='600'> <tbody><tr> <td valign='bottom' width='600' style='padding-top:0px;padding-right:20px;padding-left:20px;padding-bottom:10px'><table align='left' border='0' cellpadding='0' cellspacing='0' width='100%'> <tbody><tr> <td valign='bottom' style='color:#ffffff;padding-top:10px;font-family:Helvetica;font-size:12px;line-height:150%;text-align:left'>Corporate Contacts Ltd.<br>Beverley, UK, HU17 0LD<br>Manchester, NH 03101</td><td valign='bottom' style='color:#ffffff;padding-top:10px;font-family:Helvetica;font-size:12px;line-height:150%;text-align:left'>Phone: +44 1482 869700<br>E-Mail: [email protected]</td></tr></tbody></table> </td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></center></div></body></html>"

                    };
                    notifManager.SendNotification(notifObj);

                    userObj.Status = "Invite Sent";
                    if(userObj.isAdmin)
                        userObj.UserType = "Admin";
                    else
                        userObj.UserType = "Standard";
                    userObj.PrimaryUser = false;
                    userObj.CreatedDate = DateTime.Now;
                    userObj.LastModifiedDate = DateTime.Now;
                    userObj.Password = Encryption.EncryptStringAES(userObj.Password, rand);
                    userObj.isPasswordChange = false;
                    userObj.ConfirmPassword = userObj.Password;
                    var user = userRepository.SaveUser(userObj);
                    Session["NewUserInfo"] = "New User Added Successfully";
                    return RedirectToAction("AccountOptions");
                }
                else
                {
                    Session["NewUserInfo"] = "The Email address is already a User";
                    return RedirectToAction("NewUser");
                }
            }
            else
            {
                return View(userObj);
            }
        }
 public ActionResult ResetPassword(ForgotPasswordModel viewModel)
 {
     if (ModelState.IsValid)
     {
         User user = new User();
         user = userRepository.Users.FirstOrDefault(aid => aid.AccountID == viewModel.AccountID);
         user.Password = Encryption.EncryptStringAES(viewModel.Password, rand);
         userRepository.SaveUser(user);
         //Encryption.EncryptStringAES(sgnv.User.Password, rand);
     }
     ViewBag.MessagePass = "******";
     return View();
 }
        public ActionResult ChangePassword(User userObj)
        {
            User LoggedInUserObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];

            //var userToEdit = CCUserRepository.Users.Where(u => u.ID == userObj.ID).FirstOrDefault();

            //var test = Encryption.DecryptStringAES(LoggedInUserObj.Password, rand);

            if (Encryption.DecryptStringAES(LoggedInUserObj.Password, rand) == userObj.CurrentPassword)
            {

                if (userObj.Password != userObj.ConfirmPassword)
                {
                    Session["NewUserInfo"] = "Make sure you enter the New Passwords in both places correctly";
                    return RedirectToAction("ChangePassword");
                }
                else {
                    LoggedInUserObj.Password = Encryption.EncryptStringAES(userObj.Password, rand);
                    LoggedInUserObj.isPasswordChange = true;
                    var user = userRepository.SaveUser(LoggedInUserObj);
                    Session["user"] = user;
                    Session["NewUserInfo"] = "User Password Changed Successfully";
                    return RedirectToAction("AccountOptions");
                }
            }
            else
            {
                Session["NewUserInfo"] = "Entered Current Password does not match Users Current Password";
                return RedirectToAction("ChangePassword");
            }
        }