Exemplo n.º 1
0
        /// <summary>
        /// 取得上課時間列表
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public IEnumerable <Infrastructure.ViewModel.CourseManage.GetWeekBySemeResponse> APPGetWeekBySeme(string token)
        {
            var tokenService  = new TokenService();
            var memberService = new MemberService();
            var checkToken    = tokenService.GetTokenInfo(token).Result;

            if (checkToken == null)
            {
                return(null);
            }
            var memberInfo = memberService.UserIdToAccount(checkToken.MemberId);

            if (memberInfo == null)
            {
                return(null);
            }

            var db          = _uow.DbContext;
            var sectionData = db.Sections.FirstOrDefault(t => t.IsNowSeme == true && t.OrgId == memberInfo.OrgId);

            if (sectionData == null)
            {
                return(null);
            }

            var dateTimeTools = new Utility.DateTimeTools();
            var responseData  = dateTimeTools.GetIntervalDateList(sectionData.StartDate.ToLocalTime(), sectionData.EndDate.ToLocalTime(), 7);

            return(responseData.OrderBy(t => t.Start_date));
        }
Exemplo n.º 2
0
        public string GetPeriodWeek(DateTime targetStartDate, DateTime targetEndDate, int orgId)
        {
            var db          = _uow.DbContext;
            var sectionData = db.Sections.FirstOrDefault(t => t.IsNowSeme == true && t.OrgId == orgId);

            if (sectionData == null)
            {
                return(null);
            }
            var dateTimeTools = new Utility.DateTimeTools();
            var weekDatas     = dateTimeTools.GetIntervalDateList(sectionData.StartDate.ToLocalTime(), sectionData.EndDate.ToLocalTime(), 7);
            var responseData  = string.Empty;
            var index         = 1;

            foreach (var weekData in weekDatas)
            {
                if (
                    (weekData.Start_date.Date <= targetStartDate.Date &&
                     weekData.End_date.Date >= targetStartDate.Date) ||
                    (weekData.Start_date.Date <= targetEndDate.Date &&
                     weekData.End_date >= targetEndDate.Date) ||
                    (targetStartDate.Date <= weekData.Start_date.Date &&
                     targetEndDate >= weekData.End_date.Date)
                    )
                {
                    responseData = string.Format("{0},{1}", responseData, index.ToString());
                }

                index++;
            }
            responseData = responseData != string.Empty && responseData != null?responseData.Substring(1, responseData.Length - 1) : responseData;

            return(responseData);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 取得使用者所有上課時間地點
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public IEnumerable <Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse> AppGetMyCourseRoomSchedule(string token)
        {
            var tokenService  = new TokenService();
            var memberService = new MemberService();
            var checkToken    = tokenService.GetTokenInfo(token).Result;

            if (checkToken == null)
            {
                return(null);
            }
            var memberInfo = memberService.UserIdToAccount(checkToken.MemberId);

            if (memberInfo == null)
            {
                return(null);
            }
            var db = _uow.DbContext;

            /*  var sqlData = (from ttb in db.TimeTable
             *               join lc in db.LearningCircle on ttb.Course_No equals lc.LearningOuterKey
             *               join wt in db.WeekTable on lc.Id equals wt.LearningCircleId
             *               join cm in db.CircleMemberRoleplay on lc.Id equals cm.CircleId
             *               orderby ttb.StartDate
             *               group ttb by new { ttb, lc.LearningOuterKey, lc.Name, wt.StartPeriod, wt.EndPeriod, wt.Place, cm.MemberId, wt.ClassWeekType, lc.Enable ,wt.Week} into g
             *               where g.Key.MemberId == memberInfo.Id && g.Key.Enable == true
             *               select new Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse
             *               {
             *                   Id=g.Key.ttb.Id,
             *                   RoomID = null,
             *                   RoomName = g.Key.Place,
             *                   ClassID = g.Key.LearningOuterKey,
             *                   ClassName = g.Key.Name,
             *                   StartDate = g.Key.ttb.StartDate.Value,
             *                   EndDate = g.Key.ttb.EndDate.Value,
             *                   StartPeriod = g.Key.StartPeriod.Value,
             *                   EndPeriod = g.Key.EndPeriod.Value,
             *                   NameOfWeekDay = g.Key.Week,
             *                   ClassWeekType = (Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse.enumClassWeekType)g.Key.ClassWeekType
             *               }).ToList();*/

            var sqlData = (from wt in db.WeekTable
                           join lc in db.LearningCircle on wt.LearningCircleId equals lc.Id
                           join cmr in db.CircleMemberRoleplay on lc.Id equals cmr.CircleId
                           group wt by new { wt, lc.LearningOuterKey, lc.Name, cmr.MemberId, lc.Enable, lc.Section, lc.StartDate, lc.EndDate } into g
                           where g.Key.MemberId == memberInfo.Id &&
                           g.Key.Enable == true
                           select new Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse
            {
                RoomID = null,
                RoomName = g.Key.wt.Place,
                ClassID = g.Key.LearningOuterKey.ToLower(),
                ClassName = g.Key.Name,
                StartDate = g.Key.wt.StartTime,
                EndDate = g.Key.wt.EndTime,
                StartPeriod = g.Key.wt.StartPeriod.Value,
                EndPeriod = g.Key.wt.EndPeriod.Value,
                NameOfWeekDay = g.Key.wt.Week,
                ClassWeekType = (Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse.enumClassWeekType)g.Key.wt.ClassWeekType
            }).ToList();

            if (sqlData.Count() <= 0)
            {
                return(null);
            }
            var response      = new List <Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse>();
            var dayOfWeek     = new Utility.DayOfWeekTools();
            var dateTimeTools = new Utility.DateTimeTools();

            //weekTable資料
            foreach (var data in sqlData)
            {
                var timeDatas = dateTimeTools.GetIntervalDateList(data.StartDate, data.EndDate, 7);
                //塞TimeTable資料
                foreach (var timeData in timeDatas)
                {
                    var endDate = timeData.Start_date.Date;
                    endDate = endDate.AddHours(timeData.End_date.ToLocalTime().Hour);
                    endDate = endDate.AddMinutes(timeData.End_date.ToLocalTime().Minute);
                    var responseData = new Infrastructure.ViewModel.CourseManage.GetMyCourseScheduleResponse()
                    {
                        ClassID         = data.ClassID,
                        ClassName       = data.ClassName,
                        ClassWeekType   = data.ClassWeekType,
                        EndDate         = endDate,
                        StartDate       = timeData.Start_date.ToLocalTime(),
                        StartPeriod     = data.StartPeriod,
                        EndPeriod       = data.EndPeriod,
                        RoomName        = data.RoomName,
                        WeekDay         = dayOfWeek.ChangeToDayOfWeek(data.NameOfWeekDay).Value,
                        NameOfWeekDay   = data.NameOfWeekDay,
                        StartPeriodTime = timeData.Start_date.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss"),
                        EndPeriodTime   = endDate.ToString("yyyy-MM-ddTHH:mm:ss")
                    };
                    response.Add(responseData);
                }

                /*    data.EndDate = data.EndDate.ToLocalTime();
                 *  data.StartDate = data.StartDate.ToLocalTime();
                 *  if (data.StartDate.DayOfWeek == dayOfWeek.ChangeToDayOfWeek(data.NameOfWeekDay)) {
                 *      //data.ClassID = data.ClassID.ToLower();
                 *      data.StartPeriodTime = data.StartDate.ToString("yyyy-MM-ddTHH:mm:ss");
                 *      data.EndPeriodTime = data.EndDate.ToString("yyyy-MM-ddTHH:mm:ss");
                 *      data.WeekDay = data.StartDate.DayOfWeek;
                 *      data.NameOfWeekDay = dayOfWeek.ChangeToCht(data.StartDate.DayOfWeek);
                 *      response.Add(data);
                 *  }*/
            }
            return(response);
        }