public ActionResult EditUser(string id)
        {
            if (id == null)
            {
                RedirectToAction("Index");
            }
            List <SelectListItem> rolList = new List <SelectListItem>();
            var roles = MemberschipTools.NewRoleManager().Roles.ToList();

            roles.ForEach(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.Id
            });
            ViewBag.roles = rolList;
            var userManager = MemberschipTools.NewUserManager();
            var user        = userManager.FindById(id);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }
            var model = new UsersViewModel()
            {
                UserName     = user.UserName,
                Email        = user.Email,
                Surname      = user.Surname,
                Name         = user.Name,
                RegisterDate = user.RegisterDate,
                RoleId       = user.Roles.FirstOrDefault().RoleId,
            };

            return(View(model));
        }
        public async Task <ActionResult> Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userManager = MemberschipTools.NewUserManager();
            var user        = await userManager.FindAsync(model.UserName, model.Password);

            if (user == null)
            {
                ModelState.AddModelError(string.Empty, "Böyle bir kullanıcı bulunamadı");
                return(View(model));
            }

            var authManager  = HttpContext.GetOwinContext().Authentication;
            var userIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            authManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = model.RememberMe
            }, userIdentity);

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Profile()
        {
            var userManager = MemberschipTools.NewUserManager();
            var user        = userManager.FindById(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId());
            var model       = new ProfilePasswordViewModel()
            {
                ProfileModel = new ProfileViewModel
                {
                    Id       = user.Id,
                    Email    = user.Email,
                    Name     = user.Name,
                    Surname  = user.Surname,
                    UserName = user.UserName
                }
            };

            return(View(model));
        }
        // GET: Admin
        public ActionResult Index()
        {
            var roles       = MemberschipTools.NewRoleManager().Roles.ToList();
            var userManager = MemberschipTools.NewUserManager();
            var users       = userManager.Users.ToList().Select(x => new Entity.ViewModel.UsersViewModel
            {
                Email        = x.Email,
                Name         = x.Name,
                RegisterDate = x.RegisterDate,
                Salary       = x.Salary,
                Surname      = x.Surname,
                UserId       = x.Id,
                UserName     = x.UserName,
                RoleId       = x.Roles.FirstOrDefault().RoleId,
                RoleName     = roles.FirstOrDefault(y => y.Id == userManager.FindById(x.Id).Roles.FirstOrDefault().RoleId).Name
            }).ToList();



            return(View(users));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userManager = MemberschipTools.NewUserManager();
            var checkUser   = userManager.FindByName(model.Username);

            if (checkUser != null)
            {
                ModelState.AddModelError(string.Empty, "Bu kullanıcı zaten kayıtlı!");
                return(View(model));
            }//register işlemi yapılır



            checkUser = userManager.FindByEmail(model.Email);
            if (checkUser != null)
            {
                ModelState.AddModelError(string.Empty, "Bu e posta adresi kullanılmaktadır");
                return(View(model));
            }

            var             activationCode = Guid.NewGuid().ToString();
            ApplicationUser user           = new ApplicationUser()
            {
                Name           = model.Name,
                Surname        = model.Surname,
                Email          = model.Email,
                UserName       = model.Username,
                ActivationCode = activationCode
            };
            var response = userManager.Create(user, model.Password);

            if (response.Succeeded)
            {
                string siteUrl = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port);

                if (userManager.Users.Count() == 1)
                {
                    userManager.AddToRole(user.Id, "Admin");

                    await SiteSettings.SendMail(new MailModel
                    {
                        To      = user.Email,
                        Subject = "Hoşgeldin Sahip",
                        Message = "Sistemizi yöneteceğin için çok mutluyuz^^"
                    });
                }
                else
                {
                    userManager.AddToRole(user.Id, "Passive");

                    await SiteSettings.SendMail(new MailModel
                    {
                        To      = user.Email,
                        Subject = "Personel Yönetimi-aktivasyon",
                        Message = $"Merhaba {user.UserName}, {user.Surname}</br> Hesabınızı aktifleştirmek için <a href='{siteUrl}/Account/Activation?code={activationCode}'> Akrtivasyon kodu</a>"
                    });
                }
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Kayıt işleminde bir hata oluştu");
                return(View(model));
            }
        }