Esempio n. 1
0
        public JsonResult roleByUser()
        {
            string area       = "system";
            string controller = "auth";
            string action     = "user";

            string userID = Request.Params["userID"];

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(HttpContext.User.Identity.Name);

                EntityObjectLib.RolePrivilege p = user.Roles.SelectMany(r => r.RolePrivileges)
                                                  .First(rp => rp.Privilege.privilegeCode.ToLower().Equals(action.ToLower()) &&
                                                         rp.Privilege.resource.resourceCode.ToLower().Equals(controller.ToLower()) &&
                                                         rp.Privilege.resource.module.moduleCode.ToLower().Equals(area.ToLower())
                                                         );

                string param = p.Parameters;

                if (string.IsNullOrEmpty(param))
                {
                    object[] userRoles =
                        mydb.Roles.GroupJoin(
                            mydb.Users.Find(userID).Roles.Select(r => r.ID)
                            , r => r.ID
                            , ru => ru
                            , (r, ru) => new { r.ID, r.roleCode, r.roleName, r.roleDescription, @checked = ru.Count() > 0, userID = userID }
                            ).ToArray();

                    // 下面报错
                    //    Unable to create a constant value of type 'EntityLib.Role '. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
                    //object[] userRoles =
                    //    mydb.Roles.GroupJoin(
                    //        mydb.Users.Find(userID).Roles //是这句上的问题,对比PrivilegeModel的rolePrivilege
                    //        , r => r.ID
                    //        , ru => ru.ID
                    //        , (r, ru) => new { r.ID, r.roleCode, r.roleName, r.roleDescription, @checked = ru.Count() > 0, userID = userID }
                    //    ).ToArray();

                    return(Json(userRoles, JsonRequestBehavior.AllowGet));
                }
                else if (param.Equals("本部门"))
                {
                    IEnumerable <EntityObjectLib.Role> orgRoles = user.Organization.Users.SelectMany(u => u.Roles);
                    object[] userRoles =
                        orgRoles.GroupJoin(
                            mydb.Users.Find(userID).Roles
                            //.Where(r => orgRoles.Contains(r))
                            .Select(r => r.ID)
                            , r => r.ID
                            , ru => ru
                            , (r, ru) => new { r.ID, r.roleCode, r.roleName, r.roleDescription, @checked = ru.Count() > 0, userID = userID }
                            ).ToArray();

                    return(Json(userRoles, JsonRequestBehavior.AllowGet));
                }
                return(null);
            }
        }
Esempio n. 2
0
File: User.cs Progetto: uwitec/mb-oa
        public ActionResult updateUserRoles()
        {
            IEnumerable <string> Ids = Request.Params["IDs"].Split(",".ToArray()).AsEnumerable(); //新的角色ID串
            string userID            = Request.Params["userID"];

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(userID);

                IQueryable <string> OriRoleIDs = user.Roles.Select(r => r.ID) == null ? null : user.Roles.Select(r => r.ID).AsQueryable();

                OriRoleIDs.Load();

                string[] removeIDS = OriRoleIDs.Except(Ids).ToArray();
                foreach (string s in removeIDS)
                {
                    user.Roles.Remove(mydb.Roles.Find(s));
                }

                string[] appendIDS = Ids.Except(OriRoleIDs).ToArray();
                foreach (string s in appendIDS)
                {
                    user.Roles.Add(mydb.Roles.Find(s));
                }
                mydb.SaveChanges();
            }
            return(Json(new { success = true }));
        }
Esempio n. 3
0
File: User.cs Progetto: uwitec/mb-oa
 public ActionResult DeleteUser()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.User p = mydb.Users.Find(Request.Form["ID"]);
         mydb.Users.Remove(p);
         mydb.SaveChanges();
     }
     return(Json(new { success = true }));
 }
Esempio n. 4
0
        public ActionResult mydesk()
        {
            string userID = this.User.Identity.Name;

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(userID);
                TempData["layoutData"] = string.IsNullOrEmpty(user.LayoutData) ? "[[],[],[]]" : user.LayoutData;
            }

            return(View());
        }
Esempio n. 5
0
File: User.cs Progetto: uwitec/mb-oa
        public ActionResult UpdateUser()
        {
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User p = getUser(Request, mydb);
                ////mydb.Modules.Attach(p);
                //mydb.Entry<EntityObjectLib.User>(p).State = System.Data.EntityState.Modified;
                //mydb.Entry<EntityObjectLib.Organization>(p.Organization).State = System.Data.EntityState.Modified;
                mydb.SaveChanges();
            }

            return(Json(new { success = true }));
        }
Esempio n. 6
0
File: User.cs Progetto: uwitec/mb-oa
 public ActionResult getUser()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.User p = mydb.Users.Find(Request.Form["ID"]);
         return(Json(new
         {
             success = true,
             data = new { p.ID, p.Code, p.Name, p.Password, mobile = p.Mobile, p.MSN, p.QQ, p.OfficePhone, p.HomePhone, p.Email, p.ExpireDate, p.Description, OrgID = p.Organization.ID, Orgname = p.Organization.Name }
         }
                     ));
     }
 }
Esempio n. 7
0
        public ActionResult save()
        {
            string userID = this.User.Identity.Name;

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(userID);
                user.LayoutData = Request.Params["LayoutData"];

                mydb.SaveChanges();
            }

            return(Json(new { success = true }));
        }
Esempio n. 8
0
File: User.cs Progetto: uwitec/mb-oa
        public ActionResult CreateUser()
        {
            //将JSON格式转换为Module类型
            //return Json(new { success = false, errors = new { clientCode = "", portOfLoading = "" } });

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User p = getUser(Request, mydb);
                p.ID = Guid.NewGuid().ToString();
                mydb.Users.Add(p);
                mydb.SaveChanges();
            }

            return(Json(new { success = true }));
        }
Esempio n. 9
0
File: User.cs Progetto: uwitec/mb-oa
 private EntityObjectLib.User getUser(HttpRequestBase request, MyDB mydb)
 {
     EntityObjectLib.User p = mydb.Users.Find(Request.Form["ID"]);
     if (p == null)
     {
         p = new EntityObjectLib.User();
     }
     p.ID           = request.Form["ID"];
     p.Code         = request.Form["Code"];
     p.Name         = request.Form["Name"];
     p.Password     = request.Form["Password"];
     p.Email        = request.Form["Email"];
     p.Mobile       = request.Form["Mobile"];
     p.MSN          = request.Form["MSN"];
     p.QQ           = request.Form["QQ"];
     p.OfficePhone  = request.Form["OfficePhone"];
     p.HomePhone    = request.Form["HomePhone"];
     p.ExpireDate   = Convert.ToDateTime(request.Form["ExpireDate"]);
     p.Description  = request.Form["Description"];
     p.Organization = mydb.Organizations.Find(request.Form["OrgID"]);
     return(p);
 }
Esempio n. 10
0
        public ActionResult share()
        {
            string UserID = this.User.Identity.Name;

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(UserID);
                IEnumerable <EntityObjectLib.AddressBook> result =
                    user.AddressBookShares.Select(abs => abs.AddressBook)
                    .Union(user.Organization.AddressBookShares.Select(abs => abs.AddressBook))
                    .Distinct();

                return(Json(result.Select(ab => new
                {
                    ab.ID,
                    ab.Name,
                    ab.Sex,
                    ab.Company,
                    ab.Department,
                    ab.Job,
                    ab.Address,
                    ab.HomePhone,
                    ab.OfficePhone,
                    ab.Mobile,
                    ab.QQ,
                    ab.MSN,
                    ab.Email,
                    ab.BirthDay,
                    ab.Remark,
                    Creator = ab.Creator.Name,
                    ab.CreateTime,
                    Owner = ab.Owner.Name,
                    ab.LastUpdateTime
                }).ToArray()
                            , JsonRequestBehavior.AllowGet
                            ));
            }
        }
Esempio n. 11
0
        //
        // GET: http://localhost:12480/msgService/getOrgizations?user=chw&pwd=123456

        public string Index()
        {
            string userCode = Request.QueryString["user"];
            string password = Request.QueryString["pwd"];

            Response.Clear();
            Response.ContentType = "text/xml";

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password);
                if (user != null)
                {
                    mydb.Organizations.Load();
                    object[] result = mydb.Organizations.Local.Where(o => o.Parent == null).Select(o => getOrg(o.ID, mydb)).ToArray();
                    return(CJX.Object2XML(result).OuterXml);
                }
                else
                {
                    return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>");
                }
            }
        }
Esempio n. 12
0
        public JsonResult user()
        {
            // 查看当前用户获得该权限的角色来源
            // 取角色权限参数
            // 如果空,则取全部用户
            // 如果是"本部门",只取本部门用户

            string area       = "system";
            string controller = "auth";
            string action     = "user";

            //////////////////////////

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(HttpContext.User.Identity.Name);
                //EntityObjectLib.RolePrivilege p = mydb.RolePrivileges
                //    .Where(rp => rp.Privilege.privilegeCode.ToLower().Equals(action.ToLower())
                //        && rp.Privilege.resource.resourceCode.ToLower().Equals(controller.ToLower())
                //        && rp.Privilege.resource.module.moduleCode.ToLower().Equals(area.ToLower())
                //        ).First(rp => rp.Role.Subjects.OfType<EntityObjectLib.User>().Contains(user));
                //&& rp.Role.Subjects.OfType<EntityObjectLib.User>().Contains(user));
                //&& mydb.Users.Find(HttpContext.User.Identity.Name).Roles.Contains(rp.Role));

                EntityObjectLib.RolePrivilege p = user.Roles.SelectMany(r => r.RolePrivileges)
                                                  .First(rp => rp.Privilege.privilegeCode.ToLower().Equals(action.ToLower()) &&
                                                         rp.Privilege.resource.resourceCode.ToLower().Equals(controller.ToLower()) &&
                                                         rp.Privilege.resource.module.moduleCode.ToLower().Equals(area.ToLower())
                                                         );

                string param = p.Parameters;

                if (string.IsNullOrEmpty(param))
                {
                    return
                        (Json(mydb.Users
                              .OrderBy(u => u.Code)
                              .Select(u =>
                                      new
                    {
                        u.ID,
                        u.Code,
                        u.Name,
                        u.Password,
                        OrgID = u.Organization.ID,
                        Organization = u.Organization.Name
                    }).ToArray()
                              , JsonRequestBehavior.AllowGet
                              ));
                }
                else if (param.Equals("本部门"))
                {
                    return(Json(
                               mydb.Users
                               .Where(u => u.Organization.ID.Equals(user.Organization.ID))
                               .OrderBy(u => u.Code)
                               .Select(u => new
                    {
                        u.ID,
                        u.Code,
                        u.Name,
                        u.Password,
                        OrgID = u.Organization.ID,
                        Organization = u.Organization.Name
                    }).ToArray()
                               , JsonRequestBehavior.AllowGet));
                }

                return(null);
            }
        }
Esempio n. 13
0
File: User.cs Progetto: uwitec/mb-oa
 private EntityObjectLib.User getUser(HttpRequestBase request,MyDB mydb)
 {
     EntityObjectLib.User p = mydb.Users.Find(Request.Form["ID"]);
     if (p == null)
     {
         p = new EntityObjectLib.User();
     }
     p.ID = request.Form["ID"];
     p.Code = request.Form["Code"];
     p.Name = request.Form["Name"];
     p.Password = request.Form["Password"];
     p.Email = request.Form["Email"];
     p.Mobile = request.Form["Mobile"];
     p.MSN = request.Form["MSN"];
     p.QQ = request.Form["QQ"];
     p.OfficePhone = request.Form["OfficePhone"];
     p.HomePhone = request.Form["HomePhone"];
     p.ExpireDate = Convert.ToDateTime(request.Form["ExpireDate"]);
     p.Description = request.Form["Description"];
     p.Organization = mydb.Organizations.Find(request.Form["OrgID"]);
     return p;
 }