Beispiel #1
0
 public ActionResult Register(RegisterModel model)
 {
     ViewbagListesi();
     var haberList = (List<HaberCl>)ViewBag.haberler;
     var haberSonList = haberList.OrderByDescending(x => x.HaberGirisTarihi).ToList();
     ViewBag.haberSonList = haberSonList;
     if (ModelState.IsValid)
     {
         HaberUser user = new HaberUser();
         user.Name = model.Name;
         user.SurName = model.SurName;
         user.UserName = model.UserName;
         user.Email = model.Email;
         user.EklenmeTarihi = DateTime.Now;
         IdentityResult ir = userManager.Create(user, model.Password);
         if (ir.Succeeded)
         {
             userManager.AddToRole(user.Id, "User");
             return RedirectToAction("Login");
         }
         else
         {
             ModelState.AddModelError("RegisterUser", "Kullanıcı ekleme işleminde hata.");
         }
     }
     return View(model);
 }
Beispiel #2
0
        public ActionResult KullaniciEkle(RegisterModel model)
        {
            UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
            userManager = new UserManager<HaberUser>(userStore);

            if (ModelState.IsValid)
            {
                HaberUser user = new HaberUser();
                user.Email = model.Email;
                user.Name = model.Name;
                user.SurName = model.SurName;
                user.UserName = model.UserName;
                user.EklenmeTarihi = DateTime.Now;
                IdentityResult ir = userManager.Create(user, model.Password);
                if (ir.Succeeded)
                {
                    userManager.AddToRole(user.Id, "User");
                    return RedirectToAction("KullaniciListesi");
                }
                else
                {
                    ModelState.AddModelError("RegisterUser", "Kullanıcı ekleme işleminde hata.");
                }
            }
            return View(model);

        }
Beispiel #3
0
        public ActionResult KullaniciDuzenleme(HaberUser user, string roleID)
        {
            UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
            userManager = new UserManager<HaberUser>(userStore);
            RoleStore<HaberRole> roleStore = new RoleStore<HaberRole>(context);
            roleManager = new RoleManager<HaberRole>(roleStore);
            if (user==null)
            {
                return RedirectToAction("KullaniciListesi");
            }
            HaberRole hrole = roleManager.FindById(roleID);
            //userManager.AddToRole(user.Id, hrole.Id);
            var huser = userManager.FindByName(user.Id);
            huser.Name = user.Name;
            huser.SurName = user.SurName;
            huser.Email = user.Email;
            userManager.AddToRole(huser.Id,hrole.Name);
            if (hrole.Name=="News Writer")
            {
                yazarhelper.YazarKaydet(new Yazar { YazarAdSoyad = huser.Name + " " + huser.SurName });
            }
            context.SaveChanges();
            return RedirectToAction("KullaniciListesi");

        }
Beispiel #4
0
        public void KullaniciRolSilV(HaberUser user, string id)
        {
            UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
            userManager = new UserManager<HaberUser>(userStore);
            RoleStore<HaberRole> roleStore = new RoleStore<HaberRole>(context);
            roleManager = new RoleManager<HaberRole>(roleStore);

            userManager.RemoveFromRole(user.Id, roleManager.FindById(id).Name);
            context.SaveChanges();
        }
Beispiel #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);


            HaberContext context = new HaberContext();
            RoleStore<HaberRole> roleStore = new RoleStore<HaberRole>(context);
            RoleManager<HaberRole> roleManager = new RoleManager<HaberRole>(roleStore);

            UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
            UserManager<HaberUser> userManager = new UserManager<HaberUser>(userStore);

            if (!roleManager.RoleExists("SuperAdmin"))
            {
                HaberRole suRole = new HaberRole("SuperAdmin", "Sistem Ana Yöneticisi");
                roleManager.Create(suRole);

            }
            var user = userManager.FindByName("SuperUser");
            if (user == null)
            {
                HaberUser huser = new HaberUser
                {
                    Name = "Super",
                    SurName = "User",
                    UserName = "******",
                    EklenmeTarihi = DateTime.Now
                };

                IdentityResult ir = userManager.Create(huser, "123456");
                if (ir.Succeeded)
                {
                    userManager.AddToRole(huser.Id, "SuperAdmin");
                }


            }
            else
            {
                if (!userManager.IsInRole(user.Id, "SuperAdmin"))
                {
                    userManager.AddToRole(user.Id, "SuperAdmin");
                }
            }

            if (!roleManager.RoleExists("Admin"))
            {
                HaberRole adminRole = new HaberRole("Admin", "Yönetici");
                roleManager.Create(adminRole);
            }

            if (!roleManager.RoleExists("User"))
            {
                HaberRole userRole = new HaberRole("User", "Okuyucu, yorum yazan");
                roleManager.Create(userRole);
            }
            if (!roleManager.RoleExists("News Writer"))
            {
                HaberRole newsRole = new HaberRole("News Writer", "Haber yazarı");
                roleManager.Create(newsRole);
            }
        }