Ejemplo n.º 1
0
        public async Task <ActionResult> UpdateUserRole(string RoleID, string UserIDs)
        {
            try
            {
                if (RoleID != null && UserIDs != null)
                {
                    string[] userid = UserIDs.Split(',');
                    //Guid groleid = new Guid(RoleID);
                    int intRoleID = Convert.ToInt32(RoleID);
                    foreach (var item in userid)
                    {
                        //Guid gUserID = new Guid(item);
                        int  intUserID = Convert.ToInt32(item);
                        bool IsExist   = await UserRoleRepository.ExistAsync(ur => ur.RoleID == intRoleID && ur.UserID == intUserID);

                        if (!IsExist)
                        {
                            UserRole ur = new UserRole();
                            ur.RoleID = intRoleID;
                            ur.UserID = intUserID;
                            UserRoleRepository.Add(ur);
                        }
                    }
                    return(Json(new
                    {
                        Success = true
                    }));
                }
                return(Json(new
                {
                    Success = false
                }));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "更新用户角色失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false
                }));
            }
        }