Beispiel #1
0
        /// <summary>
        /// 根据电话号码/邮箱/中文名/英文名/QQ号获取员工的基本信息
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <returns>用户信息</returns>
        public UserModel GetUserDetail(SingleUserModel model)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var entity =
                    dbContext.Users.FirstOrDefault(
                        it =>
                        (!string.IsNullOrEmpty(model.Phone) && model.Phone == it.Phone) ||
                        (!string.IsNullOrEmpty(model.Email) && model.Email == it.Email) ||
                        (!string.IsNullOrEmpty(model.ChineseName) && model.ChineseName == it.ChineseName) ||
                        (!string.IsNullOrEmpty(model.EnglishName) && model.EnglishName == it.EnglishName) ||
                        (!string.IsNullOrEmpty(model.QQID) && model.QQID == it.QQID));

                if (entity != null)
                {
                    var user = entity.ToModel();
                    user.AuthNotify = ConvertNotifyAuth(entity.AuthNotify);
                    UserExtentions.FillRelatedDetail(dbContext, user); //填相关详细信息

                    return(user);
                }

                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 根据用户ID 获取员工的基本信息
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns>用户基本信息</returns>
        public UserModel GetUserDetail(int userId)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var entity = dbContext.Users.FirstOrDefault(it => it.Id == userId);

                if (entity != null)
                {
                    var user = entity.ToModel();
                    user.AuthNotify = ConvertNotifyAuth(entity.AuthNotify);
                    UserExtentions.FillRelatedDetail(dbContext, user); //填相关详细信息

                    return(user);
                }

                return(null);
            }
        }
        /// <summary>
        /// 根据Token获取用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public UserModel GetMemberByToken(string token)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var entity = dbContext.Users.FirstOrDefault(it => !string.IsNullOrEmpty(it.Token) && it.Token == token);

                if (entity == null)
                {
                    Log.Error(string.Format("无效的Token: {0}", token));
                    throw new KeyNotFoundException("Cannot find the current user by token.");
                }

                var user = entity.ToModel();
                user.AuthNotify = UserService.ConvertNotifyAuth(entity.AuthNotify);
                UserExtentions.FillRelatedDetail(dbContext, user); //填相关详细信息

                return(user);
            }
        }
Beispiel #4
0
        public ListResult <UserModel> List(int pageNo, int pageSize, SortModel sort, FilterModel filter)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var list = dbContext.Users.AsEnumerable();
                if (filter != null && filter.Member == "ChineseName")
                {
                    switch (filter.Operator)
                    {
                    case "IsEqualTo":
                        list = list.Where(it => it.ChineseName == filter.Value);
                        break;

                    case "IsNotEqualTo":
                        list = list.Where(it => it.ChineseName != filter.Value);
                        break;

                    case "StartsWith":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().StartsWith(filter.Value.ToLower()));
                        break;

                    case "Contains":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "DoesNotContain":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                !it.ChineseName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "EndsWith":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().EndsWith(filter.Value.ToLower()));
                        break;
                    }
                }
                if (filter != null && filter.Member == "EnglishName")
                {
                    switch (filter.Operator)
                    {
                    case "IsEqualTo":
                        list = list.Where(it => it.EnglishName == filter.Value);
                        break;

                    case "IsNotEqualTo":
                        list = list.Where(it => it.EnglishName != filter.Value);
                        break;

                    case "StartsWith":
                        list =
                            list.Where(
                                it =>
                                it.EnglishName != null &&
                                it.EnglishName.ToLower().StartsWith(filter.Value.ToLower()));
                        break;

                    case "Contains":
                        list =
                            list.Where(
                                it =>
                                it.EnglishName != null &&
                                it.EnglishName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "DoesNotContain":
                        list =
                            list.Where(
                                it =>
                                it.EnglishName != null &&
                                !it.EnglishName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "EndsWith":
                        list =
                            list.Where(
                                it =>
                                it.EnglishName != null &&
                                it.EnglishName.ToLower().EndsWith(filter.Value.ToLower()));
                        break;
                    }
                }
                if (filter != null && filter.Member == "Phone")
                {
                    switch (filter.Operator)
                    {
                    case "Contains":
                        list =
                            list.Where(it => it.Phone != null && it.Phone.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    default:
                        break;
                    }
                }

                if (filter != null && filter.Member == "ChineseName")
                {
                    switch (filter.Operator)
                    {
                    case "IsEqualTo":
                        list = list.Where(it => it.ChineseName == filter.Value);
                        break;

                    case "IsNotEqualTo":
                        list = list.Where(it => it.ChineseName != filter.Value);
                        break;

                    case "StartsWith":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().StartsWith(filter.Value.ToLower()));
                        break;

                    case "Contains":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "DoesNotContain":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                !it.ChineseName.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "EndsWith":
                        list =
                            list.Where(
                                it =>
                                it.ChineseName != null &&
                                it.ChineseName.ToLower().EndsWith(filter.Value.ToLower()));
                        break;
                    }
                }
                if (filter != null && filter.Member == "No")
                {
                    switch (filter.Operator)
                    {
                    case "IsEqualTo":
                        list = list.Where(it => it.No == filter.Value);
                        break;

                    case "IsNotEqualTo":
                        list = list.Where(it => it.No != filter.Value);
                        break;

                    case "StartsWith":
                        list = list.Where(it => it.No != null && it.No.ToLower().StartsWith(filter.Value.ToLower()));
                        break;

                    case "Contains":
                        list = list.Where(it => it.No != null && it.No.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "DoesNotContain":
                        list = list.Where(it => it.No != null && !it.No.ToLower().Contains(filter.Value.ToLower()));
                        break;

                    case "EndsWith":
                        list = list.Where(it => it.No != null && it.No.ToLower().EndsWith(filter.Value.ToLower()));
                        break;
                    }
                }

                if (sort != null)
                {
                    switch (sort.Member)
                    {
                    case "CreatedTime":
                        if (sort.Direction == SortDirection.Ascending)
                        {
                            list = list.OrderBy(item => item.CreatedTime);
                        }
                        else
                        {
                            list = list.OrderByDescending(item => item.CreatedTime);
                        }
                        break;

                    default:
                        break;
                    }
                }

                var count = list.Count();

                list = list.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();

                ListResult <UserModel> result = new ListResult <UserModel>();
                result.Data = new List <UserModel>();
                list.ToList().ForEach(item =>
                {
                    var userModel = item.ToModel();
                    UserExtentions.FillRelatedDetail(dbContext, userModel); //填相关详细信息
                    result.Data.Add(userModel);
                });

                result.Total = count;
                return(result);
            }
        }