Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        ///<param name="schoolId">学校Id</param>
        /// <param name="classCode">班级编号</param>
        /// <returns></returns>
        public static ClassRenewEntity GetStudentRenewInfoListByClassCode(int schoolId, string classCode)
        {
            var classRenewEntity = new ClassRenewEntity();

            try
            {
                var apiUrl = Config.RenewApiUrl;
                var dict   = new Dictionary <string, string>();
                var method = "GetStudentRenewInfoListByClassCode";                 //方法名称,固定值
                dict.Add("appId", Config.AppId);
                dict.Add("method", method);
                dict.Add("schoolId", schoolId.ToString());
                dict.Add("classCode", classCode);
                var sign = Helper.GetSign(dict);
                dict.Add("sign", sign);
                var result = Helper.DoPost(apiUrl, dict);                 //提交post请求
                result = result.Replace("\r\n", "").Replace("\\", "");
                var resultData = Helper.FromJsonTo <Result <List <StudentRenewModel> > >(result);
                if (resultData.State == 1 && resultData.Data != null)
                {
                    var data             = resultData.Data;
                    var renewStudents    = data.Where(t => t.isRenew == 1).ToList();
                    var notRenewStudents = data.Where(t => t.isRenew != 1).ToList();
                    classRenewEntity.RenewStudents    = renewStudents;
                    classRenewEntity.NotRenewStudents = notRenewStudents;
                    #region 已续班学员头像
                    if (renewStudents != null && renewStudents.Count > 0)
                    {
                        var userIds = string.Join(",", renewStudents.Where(t => t.userId != "").Select(t => t.userId).ToArray());
                        userIds = userIds.TrimEnd(',');
                        var avatars = UserService.GetUserAvatar(userIds);
                        for (int i = 0; i < renewStudents.Count; i++)
                        {
                            var student = renewStudents[i] as StudentRenewModel;
                            if (string.IsNullOrWhiteSpace(student.userId))
                            {
                                continue;
                            }

                            var avatar = avatars.Where(t => t.UserId == student.userId).FirstOrDefault();
                            if (avatar != null && !(string.IsNullOrWhiteSpace(avatar.Avatar)))
                            {
                                student.avatar = avatar.Avatar;
                            }
                            else
                            {
                                student.avatar = "";
                            }
                        }
                    }
                    #endregion
                    #region 未续班学员头像
                    if (notRenewStudents != null && notRenewStudents.Count > 0)
                    {
                        var userIds = string.Join(",", notRenewStudents.Where(t => t.userId != "").Select(t => t.userId).ToArray());
                        userIds = userIds.TrimEnd(',');
                        var avatars = UserService.GetUserAvatar(userIds);
                        for (int i = 0; i < notRenewStudents.Count; i++)
                        {
                            var student = notRenewStudents[i] as StudentRenewModel;
                            if (string.IsNullOrWhiteSpace(student.userId))
                            {
                                continue;
                            }
                            var avatar = avatars.Where(t => t.UserId == student.userId).FirstOrDefault();
                            if (avatar != null && !(string.IsNullOrWhiteSpace(avatar.Avatar)))
                            {
                                student.avatar = avatar.Avatar;
                            }
                            else
                            {
                                student.avatar = "";
                            }
                        }
                    }
                    #endregion
                    return(classRenewEntity);
                }
                return(classRenewEntity);
            }
            catch (Exception ex)
            {
                return(classRenewEntity);
            }
        }