예제 #1
0
        /// <summary>
        /// Создать задание
        /// </summary>
        /// <param name="document"></param>
        /// <param name="kindId"></param>
        /// <param name="performers"></param>
        /// <param name="end"></param>
        /// <param name="taskName"></param>
        /// <param name="taskContent"></param>
        /// <returns></returns>
        public Task CreateTask(Document document, Guid kindId, List <StaffEmployee> performers, DateTime end, string taskName, string taskContent)
        {
            ITaskService     TaskService     = context.ObjectContext.GetService <ITaskService>();
            ITaskListService TaskListService = context.ObjectContext.GetService <ITaskListService>();
            IStaffService    StaffService    = context.ObjectContext.GetService <IStaffService>();

            KindsCardKind kind = context.ObjectContext.GetObject <KindsCardKind>(kindId);
            Task          task = TaskService.CreateTask(kind);

            try {
                TaskService.InitializeDefaults(task);

                task.MainInfo.Name      = taskName;
                task.Description        = taskName;
                task.MainInfo.Author    = StaffService.GetCurrentEmployee();
                task.MainInfo.StartDate = DateTime.Now;
                task.MainInfo.EndDate   = end;
                task.MainInfo.Content   = taskContent;
                //myTask.Preset.Completion.ReportRequired = false;

                foreach (StaffEmployee performer in performers)
                {
                    TaskService.AddSelectedPerformer(task.MainInfo, performer);
                }

                TaskSetting taskSettings = TaskService.GetKindSettings(kind);
                //добавляем ссылку на родительскую карточку
                TaskService.AddLinkOnParentCard(task, taskSettings, document);
                //добавляем ссылку на задание в карточку
                TaskListService.AddTask(document.MainInfo.Tasks, task, document);
                //создаем и сохраняем новый список заданий
                TaskList newTaskList = TaskListService.CreateTaskList();
                context.ObjectContext.SaveObject <TaskList>(newTaskList);
                //записываем в задание
                task.MainInfo.ChildTaskList = newTaskList;

                context.ObjectContext.SaveObject(task);
                context.ObjectContext.SaveObject(document);
            } catch (Exception ex) {
                throw new Exception("Во время создания задания произошла ошибка", ex);
            }
            return(task);
        }