// GET: Error
        //public ActionResult Unathorized([Bind(Include = "Role,UserName")] IntraRole role)
        public ActionResult Unauthorized(string Role, string UserName)
        {
            IntraRole intrarole = new IntraRole
            {
                Role     = Role,
                UserName = UserName
            };

            return(View(intrarole));
        }
        public ActionResult Edit([Bind(Include = "Role_ID,Role,Admin,UsefullLimks,WS_ViewVisit,WS_CreateVisit,WS_DelCompany,WS_Settings,T2rT_RecordChecklist,T2rT_EditChecklist")] IntraRole intraRole)
        {
            var role = UserRole();

            if (!role.Admin)
            {
                return(RedirectToAction("Unauthorized", "Error", new { role.Role, role.UserName }));
            }

            //itt kellene kikeresni (find(id)) a megfelelő kategóriákat
            //category = db.Categories.Find(id);

            //ezzel bemutatom az intraRole-t az EntityFramework-nek
            //innen fogja tudni majd betölteni a navigációs property-t is
            //db.IntraRoles.Attach(intraRole);//

            //ezzel az adatok mentését készítem elő
            //var roleEntry = db.Entry(intraRole);

            //betölti a navigációs property-t (ha nem kommentelném ki)
            //ezzel egyidőben az EntityFramework tudomást szerez a létezéséről és a változást már el is menti
            //roleEntry.Reference(x => x.Category)
            //    .Load();

            //beállítja a megfelelő kategóriát
            //intraRole.Category = category

            //ModelState.Clear();
            //var isValid = TryUpdateModel(intraRole);

            var model = db.IntraRoles.Find(intraRole.Role_ID);

            if (model == null)
            {
                return(HttpNotFound());
            }

            model.Assign(intraRole);

            ModelState.Clear();
            TryUpdateModel(model);
            if (ModelState.IsValid)
            {
                //ez jelzi az EF-nek, hogy módosult az intraRole
                //roleEntry.State = EntityState.Modified;

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var role = UserRole();

            if (!role.Admin)
            {
                return(RedirectToAction("Unauthorized", "Error", new { role.Role, role.UserName }));
            }

            IntraRole intraRole = db.IntraRoles.Find(id);

            db.IntraRoles.Remove(intraRole);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
        protected IntraRole UserRole()
        {
            //public string name = User.Identity.Name;
            //private IntraRole role = new IntraRole(User.Identity.Name);
            IntraRole role = new IntraRole(User.Identity.Name);
            IEnumerable <IntraRole> roles = db.IntraRoles;

            foreach (IntraRole r in roles)
            {
                if (r.Role == "Informatikai vezetők")
                {
                    role.Add(r);
                }
            }
            ViewBag.role = role;
            return(role);
        }
        public ActionResult Create([Bind(Include = "Role,Admin,UsefullLimks,WS_ViewVisit,WS_CreateVisit,WS_DelCompany,WS_Settings,T2rT_RecordChecklist,T2rT_EditChecklist")] IntraRole intraRole)
        {
            var role = UserRole();

            if (!role.Admin)
            {
                return(RedirectToAction("Unauthorized", "Error", new { role.Role, role.UserName }));
            }

            if (ModelState.IsValid)
            {
                db.IntraRoles.Add(intraRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(intraRole));
        }
        // GET: IntraRoles/Delete/5
        public ActionResult Delete(int?id)
        {
            var role = UserRole();

            if (!role.Admin)
            {
                return(RedirectToAction("Unauthorized", "Error", new { role.Role, role.UserName }));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IntraRole intraRole = db.IntraRoles.Find(id);

            if (intraRole == null)
            {
                return(HttpNotFound());
            }
            return(View(intraRole));
        }