private bool IsAllowedJobForCurrentTab(IWeekPlanJobModel weekPlanJob, JobStateType jobState)
        {
            switch (jobState)
            {
            case JobStateType.Completed:
            {
                return(weekPlanJob.StatusId == JobStatus.Completed);
            }

            case JobStateType.NotCompleted:
            {
                int currentWeekNumber = DateTime.Now.GetWeekNumber();
                int currentYear       = DateTime.UtcNow.Year;

                return(weekPlanJob.StatusId.In(JobStatus.Canceled, JobStatus.Expired) ||
                       (weekPlanJob.StatusId != JobStatus.Completed &&
                        (weekPlanJob.Year < currentYear || (weekPlanJob.Year == currentYear && weekPlanJob.WeekNumber < currentWeekNumber))));
            }

            default:
            {
                return(weekPlanJob.StatusId != JobStatus.Completed &&
                       weekPlanJob.StatusId != JobStatus.Canceled &&
                       weekPlanJob.StatusId != JobStatus.Expired);
            }
            }
        }
        private Expression <Func <DayAssign, bool> > GetQuery(JobStateType jobStateType)
        {
            Expression <Func <DayAssign, bool> > filter = i => true;

            switch (jobStateType)
            {
            case JobStateType.Completed:
            {
                filter = filter.And(f => f.StatusId == JobStatus.Completed);
                break;
            }

            case JobStateType.NotCompleted:
            {
                int currentWeekNumber = DateTime.Now.GetWeekNumber();
                int currentYear       = DateTime.UtcNow.Year;
                filter = filter.And(f => f.StatusId == JobStatus.Canceled ||
                                    (f.StatusId != JobStatus.Completed &&
                                     (f.Year < currentYear || (f.Year == currentYear && f.WeekNumber < currentWeekNumber))));
                break;
            }

            case JobStateType.InProgress:
            {
                filter = filter.And(f => f.StatusId != JobStatus.Completed && f.StatusId != JobStatus.Canceled);
                break;
            }

            default:
                throw new NotImplementedException("GetQuery doesn't implement JobStateType: " + jobStateType);
            }

            return(filter);
        }
Beispiel #3
0
        /// <inheritdoc/>
        public void SetState(IJob job, JobStateType state)
        {
            var jobData = this.m_jobStates.FirstOrDefault(o => o.JobId == job.Id);

            if (jobData == null)
            {
                jobData = new XmlJobState()
                {
                    JobId         = job.Id,
                    CurrentState  = state,
                    LastStartTime = DateTime.Now
                };
                this.m_jobStates.Add(jobData);
            }

            // Determine state transition
            switch (state)
            {
            case JobStateType.Running:
                if (!jobData.IsRunning())
                {
                    jobData.LastStartTime = DateTime.Now;
                    jobData.LastStopTime  = null;
                }
                break;

            case JobStateType.Starting:
                jobData.LastStartTime = DateTime.Now;
                jobData.LastStopTime  = null;
                break;

            case JobStateType.Completed:
                jobData.LastStopTime = DateTime.Now;
                break;
            }
            jobData.CurrentState = state;

            this.SaveState();
        }
        private IEnumerable <IWeekPlanListViewModel> GetListViewModel(IWeekPlanGridModel weekPlanModel, JobStateType jobState)
        {
            IEnumerable <IWeekPlanJobModel> weekPlanJobList = weekPlanModel.BackLogJobs.Concat(weekPlanModel.WeekJobs);

            foreach (var job in weekPlanJobList)
            {
                //TODO Replace IsAllowedJobForCurrentTab
                if (IsAllowedJobForCurrentTab(job, jobState))
                {
                    yield return(new WeekPlanListViewModel
                    {
                        Id = job.Id,
                        Title = job.Title,
                        StatusId = job.StatusId,
                        AssignDate = GetJobAssignDate(job),
                        DayAssignId = job.DayAssignId,
                        GroupName = job.GroupName,
                        DepartmentName = job.DepartmentName,
                        Users = job.Users,
                        JobType = job.JobType,
                        Address = job.Address,
                        TimeDate = job.DayAssignDate,
                        IsAssignedToAllUsers = job.IsAssignedToAllUsers,
                        SpentTime = job.SpentTime,
                        EstimatedTime = job.Estimate,
                        WeekDay = GetWeekDay(job),
                        WeekNumber = job.WeekNumber,
                        HasChangeStatusComment = job.IsCommentExistOnAnyStatus,
                        IsUrgent = job.IsUrgent
                    });
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Changes the state of the job
 /// </summary>
 /// <param name="type">The type to change the current status to</param>
 /// <param name="description">An optional description of the change</param>
 public virtual void UpdateState(JobStateType type, string description = null)
 {
     LastModified     = DateTime.UtcNow;
     StateDescription = description;
     State            = type;
 }