Esempio n. 1
0
        public static TaskBLL CreateTaskBll(Task dalTask)
        {
            TimedTaskSettingsInfo ttsi = null;
            if (dalTask.TimedTaskSettings != null)
            {
                ttsi = new TimedTaskSettingsInfo();
                ttsi.DueTime = dalTask.TimedTaskSettings.DueTime;
                ttsi.TimeoutAction = (TaskTimeoutActions)dalTask.TimedTaskSettings.TimeoutActionID;
            }

            return  new TaskBLL(dalTask.ItemID, dalTask.ParentGroupID,
                                      new TaskInfo(dalTask.Title, dalTask.BackgroundColor, dalTask.FontColor, dalTask.FontName, dalTask.FontSize, dalTask.BeginTime, dalTask.Details),
                                      (TaskStatuses)dalTask.StatusID, dalTask.ResolveTime, ttsi);
        }
        public bool AddNewTask(TaskInfo taskInfo, int? parentGroupId,
            TimedTaskSettingsInfo timingInfo, out string errors)
        {
            errors = "";

            if (taskInfo == null)
            {
                errors = "The provided TaskInfo object is null.";
                return false;
            }

            Task taskToAdd = new Task();
            TaskInfoToTask(taskInfo, taskToAdd);
            taskToAdd.StatusID = 100;
            taskToAdd.ParentGroupID = parentGroupId;

            bool taskIsValid = true;
            bool timingInfoIsValid = true;

            string taskValidationErrs = "";
            taskIsValid = ValidateTask(taskToAdd, out taskValidationErrs);

            TimedTaskSettings newTTS = null;

            string ttsValidationErrs = "";
            if (timingInfo != null)
            {
                newTTS = new TimedTaskSettings();
                TTSInfoToTTS(timingInfo, newTTS);

                timingInfoIsValid = ValidateTimedTaskSettings(newTTS, out ttsValidationErrs);
            }

            if (!taskIsValid || !timingInfoIsValid)
                errors += taskValidationErrs + ttsValidationErrs;
            else
            {

                int newTaskKey = HardSettingsManager.GetAndAdvanceNextChecklistElementKey(_context);

                if (newTaskKey != -1)
                {
                    if (newTTS != null)
                    {
                        //sigh.. validate this too?
                        newTTS.TimedTaskSettingsID = HardSettingsManager.GetAndAdvanceNextTimedTaskSettingsKey(_context);

                        taskToAdd.TimedTaskSettings = newTTS;
                    }

                    taskToAdd.ItemID = newTaskKey;
                    BLLUtility.AddPositionInfo(_context, taskToAdd, parentGroupId);

                    _context.ChecklistElements.AddObject(taskToAdd);
                    _context.SaveChanges();

                    return true;
                }
                else
                    errors += "The next-key information could not be retreived from the database.\n";
            }

            return false;
        }
        private void TaskInfoToTask(TaskInfo ti, Task t)
        {
            BLLUtility.ChecklistElementInfoToChecklistElement(ti, t);

            t.Details = ti.Details;
        }
        private bool ValidateTask(Task task, out string errors)
        {
            errors = "";

            //using += so as to get all problems with provided Task object in one go.

            string checkListValiErrs;
            if (!BLLUtility.ValidateChecklistElement(_context, task, out checkListValiErrs))
                errors += checkListValiErrs + "\n";

            string statusIdErr = ValidateStatusId(task.StatusID);
            if (statusIdErr != null)
                errors += statusIdErr + "\n";

            string detailsErr = ValidateTaskDetails(task.Details);
            if (detailsErr != null)
                errors += detailsErr + "\n";

            if (string.IsNullOrEmpty(errors))
                return true;
            else
                return false;
        }
        private void CheckIfNewBeginTimeAffectsPosInfo(Task taskToUpdate, HardSettings settings)
        {
            int numPosTrackedDays = settings.DaysOfHistoryToShow;
            DateTime posTrackingStartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
                                                         DateTime.Now.Day - numPosTrackedDays);

            if (taskToUpdate.PositionInformation == null)
            {
                //BeginTime changed from non-pos-tracking timestamp to pos-tracking timestamp

                if (taskToUpdate.BeginTime >= posTrackingStartDate && taskToUpdate.BeginTime <= DateTime.Now)
                {
                    //need to add PositionInfo. Add task to end of Group.
                    PositionInformation pi = new PositionInformation();

                    ChecklistElement lastItemOfGroup = taskToUpdate.ParentGroup.ChecklistElements
                        .SingleOrDefault(ce => ce.PositionInformation != null && ce.PositionInformation.NextItem == null);

                    if (lastItemOfGroup != null)
                    {
                        lastItemOfGroup.PositionInformation.NextItem = taskToUpdate;
                        pi.PreviousItem = lastItemOfGroup;
                    }
                    //else the group is currently empty

                    taskToUpdate.PositionInformation = pi;
                }
            }
            else
            {
                //BeginTime changed from pos-tracking timestamp to non-pos-tracking timestamp
                //just remove PosInfo.

                if (taskToUpdate.BeginTime < posTrackingStartDate || taskToUpdate.BeginTime > DateTime.Now)
                {
                    RemovePosInfoFromLinkedList(taskToUpdate);
                }
            }
        }