Ejemplo n.º 1
0
        public List <FreeTimeEntity> GetNormalFreeTimeList(string freedateId)
        {
            List <FreeTimeEntity> list = new List <FreeTimeEntity>();
            //早上8点-晚上6点 每间隔1小时
            int star = 8;
            int end  = 18;

            for (; star < end;)
            {
                FreeTimeEntity time = new FreeTimeEntity();
                time.FreeTimeId = QSDMS.Util.Util.NewUpperGuid();
                time.FreeDateId = freedateId;
                time.StartTime  = star.ToString().PadLeft(2, '0');
                time.EndTime    = (star + 1).ToString().PadLeft(2, '0');
                time.FreeStatus = (int)RCHL.Model.Enums.FreeTimeStatus.空闲;
                list.Add(time);
                star = star + 1;
            }
            return(list);
        }
Ejemplo n.º 2
0
        public void Execute(IJobExecutionContext context)
        {
            // Console.WriteLine("当前时间: {0},下一次触发时间:{1}", DateTime.Now, context.NextFireTimeUtc);

            var teacherList = TeacherBLL.Instance.GetList(new TeacherEntity()
            {
                Status = (int)RCHL.Model.Enums.UseStatus.启用
            });

            teacherList.ForEach((o) =>
            {
                //星期
                List <FreeDateEntity> freedateList = GetCurrentWeekList();
                freedateList.ForEach((freedate) =>
                {
                    freedate.FreeDateId = Util.NewUpperGuid();
                    freedate.ObjectId   = o.TeacherId;
                    freedate.ObjectType = 2;
                    FreeDateBLL.Instance.Add(freedate);
                    //插入时间
                    List <KeyValueEntity> freetimeList = GetNormalTimeList();
                    for (int i = 0; i < freetimeList.Count; i++)
                    {
                        if ((i + 1) < freetimeList.Count)
                        {
                            FreeTimeEntity time = new FreeTimeEntity();
                            time.FreeTimeId     = Util.NewUpperGuid();
                            time.FreeDateId     = freedate.FreeDateId;
                            time.StartTime      = freetimeList[i].ItemName.ToString();
                            time.EndTime        = freetimeList[i + 1].ItemName.ToString();
                            time.FreeStatus     = (int)RCHL.Model.Enums.FreeTimeStatus.空闲;
                            FreeTimeBLL.Instance.Add(time);
                        }
                    }
                });
            });
            System.Threading.Thread.Sleep(100);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddFreeTime(string userId, string groupId, DateTime start, DateTime end)
        {
            User user = await userManager.FindByIdAsync(userId);

            Group group = groupRepository.GetGroup(groupId);

            if (user != null && group != null)
            {
                bool freeTimeEdited = false;
                if (start.CompareTo(end) >= 0)
                {
                    return(BadRequest("Event ends before it starts."));
                }
                FreeTime freeTime    = new FreeTime();
                var      timesInRepo = freeTimeRepository.GetUserFreeTime(userId);//, groupId);

                if (timesInRepo != null)
                {
                    foreach (var time in timesInRepo)
                    {
                        if ((time.StartTime < start && time.EndTime > start) ||
                            (time.StartTime < end && time.EndTime > end))
                        {
                            freeTime           = time;
                            freeTime.EndTime   = end;
                            freeTime.StartTime = start;
                            freeTimeRepository.Delete(time.Id);
                            freeTimeEdited = true;
                        }
                        else if (time.StartTime > start && time.EndTime < end)
                        {
                            freeTime           = time;
                            freeTime.EndTime   = end;
                            freeTime.StartTime = start;
                            freeTimeRepository.Delete(time.Id);
                            freeTimeEdited = true;
                        }
                        else if (time.EndTime == start)
                        {
                            freeTime         = time;
                            freeTime.EndTime = end;
                            freeTimeRepository.Delete(time.Id);
                            freeTimeEdited = true;
                        }
                        else if (time.StartTime == end)
                        {
                            freeTime           = time;
                            freeTime.StartTime = start;
                            freeTimeRepository.Delete(time.Id);
                            freeTimeEdited = true;
                        }
                    }
                }

                if (!freeTimeEdited)
                {
                    freeTime = new FreeTime
                    {
                        Id        = Guid.NewGuid().ToString(),
                        EndTime   = end,
                        StartTime = start,
                        User      = user,
                        UserId    = user.Id,
                        Group     = group,
                        GroupId   = group.GroupId
                    };
                }

                freeTimeRepository.Add(freeTime);
                FreeTimeEntity res    = new FreeTimeEntity(freeTime);
                var            result = JsonConvert.SerializeObject(res, Formatting.Indented);
                return(Content(result));
            }

            return(BadRequest("User or Group not found."));
        }