Exemplo n.º 1
0
        public ActionResult Delete(Models.RoleModel model)
        {
            if (sesion == null)
            {
                sesion = SessionDB.start(Request, Response, false, db);
            }
            model.sesion = sesion;

            if (!sesion.permisos.havePermission(Privileges[0].Permiso))
            {
                return(Json(new { msg = Notification.notAccess() }));
            }
            try
            {
                if (model.Delete())
                {
                    return(Json(new { msg = Notification.Succes("Eliminado Role con exito: " + model.Role) }));
                }
                else
                {
                    return(Json(new { msg = Notification.Error(" Error al Eliminar: " + model.Role) }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { msg = Notification.Error(e.Message) }));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(long id)
        {
            try{
                ViewBag.Head = "Roles - Edit";
                Models.RoleModel rle = new Models.RoleModel();
                CLayer.Role      rp  = BLayer.RolePermissions.GetRole(id);
                rle.Id            = rp.Id;
                rle.Name          = rp.Name;
                rle.PermissionIds = "";
                rle.Permissions   = BLayer.RolePermissions.GetAllPermissions((int)id);

                foreach (CLayer.RolePermission r in rle.Permissions)
                {
                    if (!r.HasAccess)
                    {
                        if (rle.PermissionIds == "")
                        {
                            rle.PermissionIds = r.ModuleId.ToString();
                        }
                        else
                        {
                            rle.PermissionIds = rle.PermissionIds + "," + r.ModuleId.ToString();
                        }
                    }
                }
                return(View(rle));
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/Admin/ErrorPage"));
            }
        }
Exemplo n.º 3
0
        public List <Models.RoleModel> GetRoles()
        {
            List <Models.RoleModel> Roles = new List <Models.RoleModel>(); //create a role Model list to return
            var dbCon = DBConnection;                                      // get database connection

            if (dbCon.IsConnect())                                         //check if connected.
            {
                //Set the Query
                string query = string.Format("SELECT roleid, description, rate FROM roles");
                //Create the Mysql command to be executed.
                var cmd    = new MySqlCommand(query, dbCon.Connection);
                var reader = cmd.ExecuteReader(); //execute the query

                while (reader.Read())             // read the returned reader.
                {
                    //create a new role model to add to the list to be returned
                    Models.RoleModel Role = new Models.RoleModel
                    {
                        RoleId      = int.Parse(reader["roleid"].ToString()),  //Set the Role ID from db to Model property
                        Description = reader["description"].ToString(),        //Set the Description from db to Model property
                        Rate        = decimal.Parse(reader["rate"].ToString()) //Set the rate from db to Model property
                    };

                    Roles.Add(Role); //add role model to the list to return
                }
                dbCon.Close();       //close the database
            }

            return(Roles); //return the list of roles.
        }
Exemplo n.º 4
0
        public List <Models.RoleModel> GetRoles(List <Models.RoleModel> Roles)
        {
            var dbCon = DBConnection;

            if (dbCon.IsConnect())
            {
                string query  = string.Format("SELECT roleid, description, rate FROM roles");
                var    cmd    = new MySqlCommand(query, dbCon.Connection);
                var    reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Models.RoleModel Role = new Models.RoleModel
                    {
                        RoleId      = int.Parse(reader["roleid"].ToString()),
                        Description = reader["description"].ToString(),
                        Rate        = decimal.Parse(reader["rate"].ToString())
                    };

                    Roles.Add(Role);
                }
                dbCon.Close();
            }

            return(Roles);
        }
Exemplo n.º 5
0
 public ActionResult Edit(Models.RoleModel model)
 {
     if (model.Edit())
     {
         return(Json(new JavaScriptSerializer().Serialize(model)));
     }
     return(View());
 }
Exemplo n.º 6
0
 public JsonResult UpdateRole(Models.RoleModel model)
 {
     if (ModelState.IsValid && model.Id > 0)
     {
         IDAL.IAuthoryRepository authoryRepository = EnterRepository.GetRepositoryEnter().GetAuthoryRepository;
         //判断权限名称是否已存在
         var result = authoryRepository.LoadEntities(m => m.Name == model.Name.Trim()).FirstOrDefault();
         if (result != null && result.Id != model.Id)
         {
             return(Json(new
             {
                 state = "error",
                 message = "角色名称已经存在了"
             }));
         }
         else
         {
             Model.Authory authory = new Model.Authory()
             {
                 Intro    = model.Intro,
                 Name     = model.Name,
                 OrderNum = model.OrderNum,
                 State    = model.State,
                 Id       = model.Id
             };
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.Get(m => m.Id == model.Id);
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.EditEntity(authory, new string[] { "Intro", "Name", "OrderNum", "State" });
             PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==成功", model.Name));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "修改角色成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==失败", model.Name));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "修改角色失败"
                 }));
             }
         }
     }
     else
     {
         return(Json(new
         {
             state = "error",
             message = "信息不完整"
         }));
     }
 }
Exemplo n.º 7
0
 public JsonResult AddRole(Models.RoleModel model)
 {
     if (ModelState.IsValid)
     {
         IDAL.IAuthoryRepository authoryRepository = EnterRepository.GetRepositoryEnter().GetAuthoryRepository;
         //判断权限名称是否已存在
         var result = authoryRepository.LoadEntities(m => m.Name == model.Name.Trim()).FirstOrDefault();
         if (result == null)
         {
             authoryRepository.AddEntity(new Model.Authory()
             {
                 Intro    = model.Intro,
                 Name     = model.Name,
                 OrderNum = model.OrderNum,
                 State    = model.State
             });
             //添加下操作记录
             PublicFunction.AddOperation(1, string.Format("添加角色"), string.Format("添加角色=={0}==成功", model.Name));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "添加角色成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("添加角色"), string.Format("添加角色=={0}==失败", model.Name));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "添加角色失败"
                 }));
             }
         }
         else
         {
             return(Json(new
             {
                 state = "error",
                 message = "角色名称已经存在了"
             }));
         }
     }
     else
     {
         return(Json(new
         {
             state = "error",
             message = "信息不完整"
         }));
     }
 }
Exemplo n.º 8
0
        public ActionResult Save(Models.RoleModel data)
        {
            try
            {
                CLayer.Role rp = new CLayer.Role();
                rp.Id   = data.Id;
                rp.Name = data.Name;
                long   roleId = BLayer.RolePermissions.SaveRole(rp);
                string ids    = data.PermissionIds;
                if (ids == null)
                {
                    ids = "";
                }
                if (ids != "")
                {
                    ids = ids.Trim();
                }

                if (ids == "")
                {
                    BLayer.RolePermissions.ClearBlockedPermissions(roleId);
                }
                else
                {
                    string[]   id   = ids.Split(new char[] { ',' });
                    List <int> pids = new List <int>();
                    int        j    = 0;
                    for (int i = 0; i < id.Length; i++)
                    {
                        j = 0;
                        if (int.TryParse(id[i], out j))
                        {
                            pids.Add(j);
                        }
                    }
                    if (pids.Count > 0)
                    {
                        BLayer.RolePermissions.SaveRolePermission((int)roleId, pids);
                    }
                    else
                    {
                        BLayer.RolePermissions.ClearBlockedPermissions(roleId);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/Admin/ErrorPage"));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 9
0
        public ActionResult New()
        {
            try
            {
                ViewBag.Head = "Roles - Edit";
                Models.RoleModel rle = new Models.RoleModel();
                rle.Id            = 0;
                rle.Name          = "";
                rle.PermissionIds = "";
                rle.Permissions   = BLayer.RolePermissions.GetAllPermissions();;

                return(View("Edit", rle));
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/Admin/ErrorPage"));
            }
        }
Exemplo n.º 10
0
        public Models.RoleModel GetRole(Models.RoleModel Role)
        {
            var dbCon = DBConnection;

            if (dbCon.IsConnect())
            {
                string query  = string.Format("SELECT roleid, description, rate FROM roles where roleid={0}", Role.RoleId);
                var    cmd    = new MySqlCommand(query, dbCon.Connection);
                var    reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Role.RoleId      = int.Parse(reader["roleid"].ToString());
                    Role.Description = reader["description"].ToString();
                    Role.Rate        = decimal.Parse(reader["rate"].ToString());
                }
                dbCon.Close();
            }

            return(Role);
        }
Exemplo n.º 11
0
        private static void UpdateRoles(string dir, Dictionary <string, Models.UserModel> users)
        {
            var roles = Pre600Functions.LoadContent <Pre600RoleModel>(dir);

            foreach (var roleitem in roles)
            {
                var role    = roleitem.Value;
                var newrole = new Models.RoleModel();
                newrole.Name = role.Name;

                newrole.Id = Guid.NewGuid();
                var members = new List <Guid>();
                foreach (var memberName in role.Members)
                {
                    Models.UserModel user;
                    if (users.TryGetValue(memberName, out user))
                    {
                        members.Add(user.Id);
                    }
                }
                newrole.Members = members.ToArray();
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> CreateRole(Models.RoleModel roleModel)
        {
            if (ModelState.IsValid)
            {
                IdentityRole identityRole = new IdentityRole {
                    Name = roleModel.RoleName
                };
                IdentityResult identityResult = await roleManager.CreateAsync(identityRole); //sync method

                if (identityResult.Succeeded)
                {
                    return(RedirectToAction("index", "home"));
                }

                foreach (IdentityError error in identityResult.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            //use role manager service to create role

            return(View(roleModel));
        }
Exemplo n.º 13
0
        public Models.RoleModel UpdateRole(Models.RoleModel Role)
        {
            var dbCon = DBConnection;

            if (dbCon.IsConnect())
            {
                string query = string.Format("UPDATE roles set description='{0}', rate='{1}' WHERE roleid={2};", Role.Description, Role.Rate, Role.RoleId);

                if (dbCon.Connection.State.ToString() == "Closed")
                {
                    dbCon.Connection.Open();
                }

                var cmd = new MySqlCommand(query, dbCon.Connection);


                var reader = cmd.ExecuteNonQuery();

                dbCon.Close();
            }

            return(Role);
        }
Exemplo n.º 14
0
        public Models.RoleModel CreateRole(Models.RoleModel Role)
        {
            var dbCon = DBConnection;

            if (dbCon.IsConnect())
            {
                string query = string.Format("INSERT INTO roles (description, rate) VALUES('{0}', '{1}');", Role.Description, Role.Rate);

                if (dbCon.Connection.State.ToString() == "Closed")
                {
                    dbCon.Connection.Open();
                }

                var cmd = new MySqlCommand(query, dbCon.Connection);


                var reader = cmd.ExecuteNonQuery();

                dbCon.Close();
            }

            return(Role);
        }