Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <returns>是否重置成功</returns>
        public bool ResetPassword(ResetPasswordModel model)
        {
            string tempPassword = UserExtentions.RandomPassword();
            string title        = "[OA]重置密码成功";
            string body         = "{0},你好。\r\n密码重置成功,密码为{1}。\r\n请及时修改密码。";

            if (model == null || (string.IsNullOrEmpty(model.Phone) && string.IsNullOrEmpty(model.Email)) ||
                (!string.IsNullOrEmpty(model.Email) && !model.Email.IsEmail()))
            {
                throw new Exception("Invalid reset password request.");
            }

            try
            {
                //更新用户信息
                using (var dbContext = new MissionskyOAEntities())
                {
                    //1.查找用户
                    var entity =
                        dbContext.Users.Where(
                            it =>
                            (!string.IsNullOrEmpty(it.Email) &&
                             it.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase)) ||
                            (!string.IsNullOrEmpty(it.Phone) &&
                             it.Phone.Equals(model.Phone, StringComparison.InvariantCultureIgnoreCase)))
                        .FirstOrDefault();

                    if (entity == null)
                    {
                        throw new KeyNotFoundException("cannot find user.");
                    }

                    //2.更新用户密码
                    entity.Password = (new MD5Cryptology()).Encrypt(tempPassword);
                    entity.Status   = (int)AccountStatus.RestPassword;

                    dbContext.SaveChanges();

                    //3.发送邮件
                    EmailClient.Send(new List <string> {
                        entity.Email
                    }, null, title,
                                     string.Format(body, entity.EnglishName, tempPassword));
                }

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 5
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);
            }
        }