public ActionResult Create(Role m)
        {
            if (ModelState.IsValid)
            {

                if (um.Create(m))
                {
                    return Redirect("/Contents/html/parent_reload.htm");
                }
            }

            ViewBag.PermissionCategories = new UPermissionCategory().GetZTreeJson();

            return View(m);
        }
Esempio n. 2
0
        public Boolean Edit(Role model)
        {
            try
            {
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                UpdateRolePermission(model);

                return true;
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return false;
            }
        }
Esempio n. 3
0
        public Boolean Create(Role model)
        {
            try
            {

                Int32 id;

                id = GetRId();

                model.R_Id = id;
                olsEni.Roles.Add(model);
                olsEni.SaveChanges();

                UpdateRolePermission(model);

                return true;
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return false;
            }
        }
Esempio n. 4
0
        public Role GetNew()
        {
            Role model;

            model = new Role()
            {
                R_Id = 0,
                R_Name = "",
                R_Permissions = "[]",
                R_PermissionCategories = "[]",
                R_Remark = "",
                R_AddTime = DateTime.Now,
                R_Status = (Byte)Status.Available
            };

            return model;
        }
Esempio n. 5
0
        private void UpdateRolePermission(Role model)
        {
            List<Role_Permission> rps;
            Int32[] permissionIds;

            rps = olsEni.Role_Permission.Where(m => m.R_Id == model.R_Id).ToList();

            foreach (var rp in rps)
            {
                olsEni.Entry(rp).State = EntityState.Deleted;
            }
            olsEni.SaveChanges();

            permissionIds = JsonConvert.DeserializeObject<Int32[]>(model.R_Permissions);

            foreach (var pId in permissionIds)
            {
                olsEni.Entry(new Role_Permission
                {
                    R_Id = model.R_Id,
                    P_Id = pId
                }).State = EntityState.Added;
            }
            olsEni.SaveChanges();
        }