Пример #1
0
        /// <summary>
        /// Configure After Capture Tasks UI
        /// </summary>
        /// <param name="config">Initial config</param>
        /// <param name="chkAfterCaptureTask_CheckedChanged">Event handler of the parent form</param>
        public void ConfigUI(Subtask config, EventHandler chkAfterCaptureTask_CheckedChanged)
        {
            var tasks = Enum.GetValues(typeof(Subtask)).Cast<Subtask>().Select(x => new
            {
                Description = x.GetDescription(),
                Enum = x
            });

            flpTasks.Controls.Clear();

            foreach (var job in tasks)
            {
                switch (job.Enum)
                {
                    case Subtask.None:
                        continue;
                }

                CheckBox chkAfterCaptureTask = new CheckBox();
                chkAfterCaptureTask.Tag = job.Enum;
                chkAfterCaptureTask.Text = job.Description;
                chkAfterCaptureTask.AutoSize = true;
                chkAfterCaptureTask.CheckedChanged += chkAfterCaptureTask_CheckedChanged;
                chkAfterCaptureTask.Checked = config.HasFlag(job.Enum);
                flpTasks.Controls.Add(chkAfterCaptureTask);
            }
        }
Пример #2
0
        public SubtaskWrapper(ProjectApiBase projectApiBase, Subtask subtask, Task task)
        {
            Id     = subtask.ID;
            Title  = subtask.Title;
            Status = (int)subtask.Status;
            if (subtask.Responsible != Guid.Empty)
            {
                Responsible = projectApiBase.GetEmployeeWraper(subtask.Responsible);
            }
            Created   = (ApiDateTime)subtask.CreateOn;
            CreatedBy = projectApiBase.GetEmployeeWraper(subtask.CreateBy);
            Updated   = (ApiDateTime)subtask.LastModifiedOn;
            if (subtask.CreateBy != subtask.LastModifiedBy)
            {
                UpdatedBy = projectApiBase.GetEmployeeWraper(subtask.LastModifiedBy);
            }
            CanEdit = ProjectSecurity.CanEdit(task, subtask);

            TaskId = task.ID;
        }
Пример #3
0
        public void Complete(TaskModel task, Subtask subtask)
        {
            if (task != null)
            {
                task.ModifiedSinceStart = true;

                if (subtask != null)
                {
                    subtask.IsCompleted = !subtask.IsCompleted;

                    if (Settings.Current.CompleteTask && !task.IsCompleted && subtask.IsCompleted)
                    {
                        if (task.Subtasks.All(s => s.IsCompleted))
                        {
                            Complete(task);
                        }
                    }
                }
            }
        }
Пример #4
0
 /*
  * Updates tasks and subtasks to complete or incomplete in the database
  * based on the current checked status
  */
 private void taskTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e)
 {
     // Check whether the node is a task or a subtask
     // in order to decide which update statements to call
     if (e.Node.Parent == null)
     {
         Models.Task tag = (Models.Task)e.Node.Tag;
         if (e.Node.Checked == false)
         {
             TaskController.updateTaskCompleted(tag.taskID);
             List <Subtask> subtasks = SubtaskController.GetSubtasksForTask(user, tag.taskID);
             foreach (Subtask st in subtasks)
             {
                 if (st.st_CompleteDate == DateTime.MaxValue)
                 {
                     SubtaskController.UpdateSubtaskToCompleted(st.subtaskID);
                 }
             }
             foreach (TreeNode node in e.Node.Nodes)
             {
                 node.Checked = true;
             }
         }
         else if (e.Node.Checked == true)
         {
             TaskController.updateTaskIncomplete(tag.taskID);
         }
     }
     else
     {
         Subtask subTag = (Subtask)e.Node.Tag;
         if (e.Node.Checked == false)
         {
             SubtaskController.UpdateSubtaskToCompleted(subTag.subtaskID);
         }
         else if (e.Node.Checked == true)
         {
             SubtaskController.UpdateSubtaskToIncomplete(subTag.subtaskID);
         }
     }
 }
Пример #5
0
        private void AddTask()
        {
            ManagerValidation MV = new ManagerValidation();
            bool correctForm     = MV.AddTaskValidation(Name, Description);

            if (correctForm)
            {
                PMSContext dbContext = new PMSContext();

                Subtask subtask = new Subtask
                {
                    Name            = Name,
                    Description     = Description,
                    StartTime       = DateTime.Now,
                    EndTime         = EndTime,
                    MainTaskID      = SelectedListOfMainTasks.MainTaskID,
                    SubtaskStatusID = 1,
                    Priority        = SelectedPriority,
                    UserID          = SelectedUser.UserID,
                    WhoCreated      = Global.user.UserID
                };


                RecentActivity ra = new RecentActivity
                {
                    DateAdded   = DateTime.Now,
                    TeamID      = (int)Global.user.TeamID,
                    Description = $"User {Global.user.FullName} has created a new task " +
                                  $"for {SelectedUser.FullName} called: {_Name}"
                };

                dbContext.Subtask.Add(subtask);
                dbContext.RecentActivity.Add(ra);
                dbContext.SaveChanges();

                setVariableWhenAddTask();

                ErrorMessage er = new ErrorMessage("Subtask created successfully!");
                er.ShowDialog();
            }
        }
Пример #6
0
        public void Refresh(double height)
        {
            Subtask subtask = Subtask;

            if (subtask == null)
            {
                return;
            }

            Icon.Visibility   = subtask.IsCompleted ? Visibility.Visible : Visibility.Collapsed;
            Text.Text         = subtask.Text;
            Strike.Visibility = subtask.IsCompleted ? Visibility.Visible : Visibility.Collapsed;
            if (subtask.IsCompleted)
            {
                Text.Opacity = 0.45;
            }

            Height = height;

            Root.Height = height;
            Root.Margin = new Thickness(0.125 * height, 0, 0, 0);

            IconBorder.Width           = height / 1.2;
            IconBorder.Height          = height / 1.2;
            IconBorder.BorderThickness = new Thickness(height / 24.0);

            Icon.Width  = height / 1.2;
            Icon.Height = height / 1.2;

            IconPath.Width  = 30.39984 * (height / 48.0);
            IconPath.Height = 25.3332 * (height / 48.0);
            Canvas.SetLeft(IconPath, height / 9.6);
            Canvas.SetTop(IconPath, height / 6.0);

            Text.FontSize = height * 0.6;
            Text.Margin   = new Thickness(height, height / 12.0, 0, 0);

            Strike.Margin          = new Thickness(height, height / 12.0, 0, 0);
            Strike.BorderThickness = new Thickness(0, 0, 0, height / 24.0);
            ((CompositeTransform)Strike.RenderTransform).TranslateY = height / 48.0;
        }
Пример #7
0
        public ActionResult View(int id)
        {
            try
            {
                Subtask S = Subtask.FetchSubtaskByID(id);
                if (S == null)
                {
                    return(null); // Need to throw an Error view
                }

                Current C = new Current();
                C.Subtask  = S;
                C.Employee = (Employee)Session["Employee"];
                InjectEmployeeDetails();
                return(View(C));
            }
            catch (Exception)
            {
                return(null); // Need to throw an Error view
            }
        }
Пример #8
0
        public SubtasksPage()
        {
            if (IsSetNavigationParameter())
            {
                _task    = NavigationParameter <TaskModel>();
                Subtasks = _task.Subtasks;
            }

            if (IsSetNavigationParameter("AddSubtask"))
            {
                if (NavigationParameter <bool>("AddSubtask"))
                {
                    _subtaskToEdit = new Subtask();
                    Subtasks.Add(_subtaskToEdit);
                }
            }

            InitializeComponent();
            DataContext = this;
            BuildAppBar();
        }
Пример #9
0
        public void Delete(Subtask subtask, Task task)
        {
            if (subtask == null)
            {
                throw new ArgumentNullException("subtask");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            ProjectSecurity.DemandEdit(task, subtask);
            DaoFactory.SubtaskDao.Delete(subtask.ID);

            var recipients = GetSubscribers(task);

            if (recipients.Any())
            {
                NotifyClient.Instance.SendAboutSubTaskDeleting(recipients, task, subtask);
            }
        }
Пример #10
0
      public ActionResult Edit1(SubTaskOperation t)
      {
          Task task = new Task();

          if (ModelState.IsValid)
          {
              foreach (var i in TaskService.tasks())
              {
                  if (i.name.Equals(t.parentname))
                  {
                      task = i;
                  }
              }

              Subtask subtask = new Subtask {
                  id = t.id, name = t.name, date = t.date, status = t.status, Task = task
              };
              TaskService.editsubtask(subtask);
          }
          return(RedirectToAction("getsubtask", new { id = task.id }));
      }
Пример #11
0
        public virtual Subtask Save(Subtask subtask)
        {
            using (var db = new DbManager(DatabaseId))
            {
                var insert = Insert(SubtasksTable)
                             .InColumnValue("id", subtask.ID)
                             .InColumnValue("task_id", subtask.Task)
                             .InColumnValue("title", subtask.Title)
                             .InColumnValue("responsible_id", subtask.Responsible.ToString())
                             .InColumnValue("status", subtask.Status)
                             .InColumnValue("create_by", subtask.CreateBy.ToString())
                             .InColumnValue("create_on", TenantUtil.DateTimeToUtc(subtask.CreateOn))
                             .InColumnValue("last_modified_by", subtask.LastModifiedBy.ToString())
                             .InColumnValue("last_modified_on", TenantUtil.DateTimeToUtc(subtask.LastModifiedOn))
                             .InColumnValue("status_changed", TenantUtil.DateTimeToUtc(subtask.StatusChangedOn))
                             .Identity(1, 0, true);

                subtask.ID = db.ExecuteScalar <int>(insert);
                return(subtask);
            }
        }
Пример #12
0
        public void IsOvertime_Test()
        {
            // ARRANGE
            var assignment = Assignment.Create(createParam);

            assignment.Subtasks.Add(Subtask.Create(new SubtaskCreateParam
            {
                Name        = "Test subtask",
                Description = "123",
                Priority    = SubtaskPriority.High
            }));

            var subtask = assignment.Subtasks.First();
            // subtask.Entries.Add(new EntryCreateParam() { Date = DateTime.Now, })

            // ACT
            var canDelete = assignment.CanDelete();

            // ASSERT
            Assert.IsFalse(canDelete);
        }
Пример #13
0
        public Subtask Copy(Subtask from, Task task)
        {
            var team = factory.ProjectEngine.GetTeam(task.Project.ID);

            var subtask = new Subtask
            {
                ID       = default(int),
                CreateBy = SecurityContext.CurrentAccount.ID,
                CreateOn = TenantUtil.DateTimeNow(),
                Task     = task.ID,
                Title    = from.Title,
                Status   = from.Status
            };

            if (team.Any(r => r.ID == from.Responsible))
            {
                subtask.Responsible = from.Responsible;
            }

            return(SaveOrUpdate(subtask, task));
        }
Пример #14
0
    private void LoadSubtaskMode(Subtask subtask, string mode)
    {
        string modeLowercase = mode.ToLower();

        switch (modeLowercase)
        {
        case "manual":
            subtask.mode = Subtask.SubtaskMode.MANUAL;
            break;

        case "auto":
            subtask.mode = Subtask.SubtaskMode.AUTO;
            break;

        case "fast":
            subtask.mode = Subtask.SubtaskMode.FAST;
            break;

        default:
            subtask.mode = Subtask.SubtaskMode.MANUAL;
            break;
        }
    }
Пример #15
0
        public SubtaskWrapper(Subtask subtask, Task task)
        {
            Id = subtask.ID;

            if (subtask.Responsible != Guid.Empty)
            {
                Responsible = EmployeeWraper.Get(subtask.Responsible);
            }

            Title   = subtask.Title;
            Status  = (int)subtask.Status;
            CanEdit = ProjectSecurity.CanEdit(task, subtask);

            CreatedBy = EmployeeWraper.Get(subtask.CreateBy);

            if (subtask.CreateBy != subtask.LastModifiedBy)
            {
                UpdatedBy = EmployeeWraper.Get(subtask.LastModifiedBy);
            }

            Updated = (ApiDateTime)subtask.LastModifiedOn;
            Created = (ApiDateTime)subtask.CreateOn;
        }
Пример #16
0
        private void NotifySubtask(Task task, Subtask subtask, List <IRecipient> recipients, bool isNew)
        {
            //Don't send anything if notifications are disabled
            if (_factory.DisableNotifications)
            {
                return;
            }

            if (isNew && recipients.Any())
            {
                NotifyClient.Instance.SendAboutSubTaskCreating(recipients, task, subtask);
            }

            if (subtask.Responsible.Equals(Guid.Empty) || subtask.Responsible.Equals(SecurityContext.CurrentAccount.ID))
            {
                return;
            }

            if (!_factory.GetTaskEngine().IsUnsubscribedToTask(task, subtask.Responsible.ToString()))
            {
                NotifyClient.Instance.SendAboutResponsibleBySubTask(subtask, task);
            }
        }
Пример #17
0
 /// <summary>
 /// Will be executed each frame while the task is running.
 /// </summary>
 public override void DoAction()
 {
     Subtask.DoAction();
     if (Subtask.Finished)
     {
         if (++iteration < iterations)
         {
             Subtask.Reset();
             if (Subtask.CheckConditions())
             {
                 Subtask.SafeStart();
             }
             else
             {
                 Finish();
             }
         }
         else
         {
             Finish();
         }
     }
 }
Пример #18
0
        public void SendAboutResponsibleBySubTask(Subtask subtask, Task task)
        {
            var recipient = ToRecipient(subtask.Responsible);

            if (recipient != null)
            {
                client.SendNoticeToAsync(
                    NotifyConstants.Event_ResponsibleForSubTask,
                    task.NotifyId,
                    new[] { recipient },
                    GetDefaultSenders(recipient),
                    null,
                    new TagValue(NotifyConstants.Tag_ProjectID, task.Project.ID),
                    new TagValue(NotifyConstants.Tag_ProjectTitle, task.Project.Title),
                    new TagValue(NotifyConstants.Tag_EntityTitle, task.Title),
                    new TagValue(NotifyConstants.Tag_SubEntityTitle, subtask.Title),
                    new TagValue(NotifyConstants.Tag_EntityID, task.ID),
                    new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable {
                    { "TaskDescription", HttpUtility.HtmlEncode(task.Description) }
                }),
                    ReplyToTagProvider.Comment("project.task", task.ID.ToString()));
            }
        }
Пример #19
0
        public async Task Consume(ConsumeContext <CreateSubtask> context)
        {
            var message = context.Message;

            if (message.TaskId == Guid.Empty)
            {
                _logger.LogWarning("Sub-task id cannot be empty.");
                return;
            }

            _logger.LogInformation("Creating sub-task [JobId = {JobId}, TaskId = {JobId}, Name = {Name}]",
                                   message.JobId,
                                   message.TaskId,
                                   message.Name);

            var job = await _dbContext
                      .Jobs.AsNoTracking()
                      .SingleOrDefaultAsync(x => x.JobId == message.JobId);

            if (job == null)
            {
                _logger.LogError("Job with ID {JobId} has not been created. Job creation may be queued and waiting. Retry.");
                throw new InvalidOperationException($"Job with ID {message.JobId} does not exist.");
            }

            var task = new Subtask()
            {
                JobId  = job.Id,
                TaskId = message.TaskId,
                Name   = message.Name,
                Meta   = message.Meta
            };

            await _dbContext.Tasks.AddAsync(task);

            await _dbContext.SaveChangesAsync();
        }
Пример #20
0
        public static void Task2(Subtask s)
        {
            Console.WriteLine("Bitte geben Sie einen Satz ein:");
            string word = Console.ReadLine();
            string[] words = word.ToLower().Split();

            if (s == Subtask.A)
            {
                int finalAmountSingle = 0,
                    finalAmountTotal = 0;
                foreach (string w in words)
                {
                    int amount = 0;
                    foreach (char c in w)
                        if (c == 'e') ++amount;

                    if (amount == 1) ++finalAmountSingle;
                    else if (amount > 1) ++finalAmountTotal;
                }
                Console.WriteLine($"Anzahl an Wörtern mit genau einem E: {finalAmountSingle}\nAnzahl an Wörtern mit mehr als einem E: {finalAmountTotal}");
            }
            else if (s == Subtask.B)
            {
                int finalAmountSingle = 0,
                    finalAmountTotal = 0;
                foreach (string w in words)
                {
                    if (w.Contains("e"))
                    {
                        ++finalAmountTotal;
                        if (w.IndexOf("e") == w.LastIndexOf("e")) ++finalAmountSingle;
                    }
                }
                Console.WriteLine($"Anzahl an Wörtern mit genau einem E: {finalAmountSingle}\nAnzahl an Wörtern mit mehr als einem E: {finalAmountTotal}");
            }
            else throw new Exception("Ungültiger Parameter");
        }
Пример #21
0
        public void SendAboutResponsibleBySubTask(Subtask subtask, Task task)
        {
            var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));

            client.AddInterceptor(interceptor);
            try
            {
                var recipient = ToRecipient(subtask.Responsible);
                if (recipient != null)
                {
                    client.SendNoticeToAsync(
                        NotifyConstants.Event_ResponsibleForSubTask,
                        task.NotifyId,
                        new[] { recipient },
                        true,
                        new TagValue(NotifyConstants.Tag_ProjectID, task.Project.ID),
                        new TagValue(NotifyConstants.Tag_ProjectTitle, task.Project.Title),
                        new TagValue(NotifyConstants.Tag_EntityTitle, task.Title),
                        new TagValue(NotifyConstants.Tag_SubEntityTitle, subtask.Title),
                        new TagValue(NotifyConstants.Tag_EntityID, task.ID),
                        new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable {
                        { "TaskDescription", HttpUtility.HtmlEncode(task.Description) }
                    }),
                        ReplyToTagProvider.Comment("project.task", task.ID.ToString(CultureInfo.InvariantCulture)),
                        new AdditionalSenderTag("push.sender"),
                        new TagValue(PushConstants.PushItemTagName, new PushItem(PushItemType.Subtask, subtask.ID.ToString(), subtask.Title)),
                        new TagValue(PushConstants.PushParentItemTagName, new PushItem(PushItemType.Task, task.ID.ToString(), task.Title)),
                        new TagValue(PushConstants.PushModuleTagName, PushModule.Projects),
                        new TagValue(PushConstants.PushActionTagName, PushAction.Assigned));
                }
            }
            finally
            {
                client.RemoveInterceptor(interceptor.Name);
            }
        }
Пример #22
0
        public static IEnumerable <Subtask> Create(Assignment assignment)
        {
            var rnd = new Random();

            var subtasks = new List <Subtask>
            {
                Subtask.Create(new SubtaskCreateParam
                {
                    Name     = subtaskNames[rnd.Next(0, 5)],
                    Priority = EnumDefinition.SubtaskPriority.High
                }),
                Subtask.Create(new SubtaskCreateParam
                {
                    Name     = subtaskNames[rnd.Next(0, 5)],
                    Priority = EnumDefinition.SubtaskPriority.Low
                }),
                Subtask.Create(new SubtaskCreateParam
                {
                    Name     = subtaskNames[rnd.Next(0, 5)],
                    Priority = EnumDefinition.SubtaskPriority.Medium
                }),
                Subtask.Create(new SubtaskCreateParam
                {
                    Name     = subtaskNames[rnd.Next(0, 5)],
                    Priority = EnumDefinition.SubtaskPriority.Lowest
                })
            }.Take(rnd.Next(0, 4));

            foreach (var s in subtasks)
            {
                s.Assignment    = assignment;
                s.Assignment_Id = assignment.Id;
            }

            return(subtasks);
        }
Пример #23
0
        public Subtask AddSubtaskToPlan(uint planId, uint spcId, uint Quantity)
        {
            var tmp = u.Get(delegate(RsTask tsk) { return(tsk.Code == planId); });

            if (tmp == null)
            {
                return(null);
            }
            var spc = u.Get(delegate(Specification sp) { return(sp.Code == spcId); });

            if (spc == null)
            {
                return(null);
            }
            var sbtsk = new Subtask(spc, (int)Quantity);

            sbtsk.NavProp = tmp;
            tmp.Subtasks.Add(sbtsk);
            u.GetAll <RsArea>().AsQueryable().OfType <WarehouseArea>().Include(x => x.Tasks).ToList().ForEach(x => x.Generator.GenerateTasks(sbtsk));
            u.GetAll <RsArea>().AsQueryable().OfType <SmtLineArea>().Include(x => x.Tasks).ToList().ForEach(x => x.Generator.GenerateTasks(sbtsk));
            u.Save();

            return(sbtsk);
        }
Пример #24
0
        public virtual Subtask Save(Subtask subtask)
        {
            using (var tr = DbManager.Connection.BeginTransaction())
            {
                var insert = Insert(Table)
                             .InColumnValue("id", subtask.ID)
                             .InColumnValue("task_id", subtask.Task)
                             .InColumnValue("title", subtask.Title)
                             .InColumnValue("responsible_id", subtask.Responsible.ToString())
                             .InColumnValue("status", subtask.Status)
                             .InColumnValue("create_by", subtask.CreateBy.ToString())
                             .InColumnValue("create_on", TenantUtil.DateTimeToUtc(subtask.CreateOn))
                             .InColumnValue("last_modified_by", subtask.LastModifiedBy.ToString())
                             .InColumnValue("last_modified_on", TenantUtil.DateTimeToUtc(subtask.LastModifiedOn))
                             .InColumnValue("status_changed", TenantUtil.DateTimeToUtc(subtask.StatusChangedOn))
                             .Identity(1, 0, true);

                subtask.ID = DbManager.ExecuteScalar <int>(insert);

                tr.Commit();
            }

            return(subtask);
        }
Пример #25
0
 public bool CanEdit(Task task, Subtask subtask)
 {
     return(Scope.Resolve <ProjectSecurityTask>().CanEdit(task, subtask));
 }
 public SubtaskWrapperFull(Subtask subtask)
     : base(subtask, subtask.ParentTask)
 {
     ParentTask = new SimpleTaskWrapper(subtask.ParentTask);
 }
Пример #27
0
        public Subtask SaveOrUpdate(Subtask subtask, Task task)
        {
            if (subtask == null)
            {
                throw new Exception("subtask.Task");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }

            // check guest responsible
            if (ProjectSecurity.IsVisitor(subtask.Responsible))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            var isNew          = subtask.ID == default(int); //Task is new
            var oldResponsible = Guid.Empty;

            subtask.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            subtask.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (subtask.CreateBy == default(Guid))
                {
                    subtask.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (subtask.CreateOn == default(DateTime))
                {
                    subtask.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandEdit(task);
                subtask = DaoFactory.SubtaskDao.Save(subtask);
            }
            else
            {
                var oldSubtask = DaoFactory.SubtaskDao.GetById(new[] { subtask.ID }).First();

                if (oldSubtask == null)
                {
                    throw new ArgumentNullException("subtask");
                }

                oldResponsible = oldSubtask.Responsible;

                //changed task
                ProjectSecurity.DemandEdit(task, oldSubtask);
                subtask = DaoFactory.SubtaskDao.Save(subtask);
            }

            NotifySubtask(task, subtask, isNew, oldResponsible);

            var senders = new HashSet <Guid> {
                subtask.Responsible, subtask.CreateBy
            };

            senders.Remove(Guid.Empty);

            foreach (var sender in senders)
            {
                Subscribe(task, sender);
            }

            return(subtask);
        }
Пример #28
0
 private void ToggleComplete(TaskModel task, Subtask subtask)
 {
     App.Tasks.Complete(task, subtask);
 }
Пример #29
0
 public SubtaskViewModel(Subtask subtask)
 {
     Subtask = subtask;
 }
 public SubtaskWrapperFull(ProjectApiBase projectApiBase, Subtask subtask)
     : base(projectApiBase, subtask, subtask.ParentTask)
 {
     ParentTask = new SimpleTaskWrapper(projectApiBase, subtask.ParentTask);
 }
Пример #31
0
        public JsonResult CreateSubTask(SubTaskRequest request)
        {
            var checkResult = CheckUsername(request.username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(request.projectId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(701, "Invalid projectId."));
            }

            if (!CornerCaseCheckHelper.Check(request.taskId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(501, "Invalid taskId."));
            }

            if (!CornerCaseCheckHelper.Check(request.subTaskName, 50, CornerCaseCheckHelper.Title))
            {
                return(JsonReturnHelper.ErrorReturn(511, "Invalid subTaskName."));
            }

            if (!CornerCaseCheckHelper.Check(request.description, 100, CornerCaseCheckHelper.Description))
            {
                return(JsonReturnHelper.ErrorReturn(602, "Invalid description."));
            }

            if (!CornerCaseCheckHelper.Check(request.principal, 50, CornerCaseCheckHelper.Username))
            {
                return(JsonReturnHelper.ErrorReturn(101, "Invalid principal."));
            }

            var user = _meshContext.Users.First(u => u.Email == request.username);

            var project = _meshContext.Projects.FirstOrDefault(p => p.Id == request.projectId);

            if (project == null)
            {
                return(JsonReturnHelper.ErrorReturn(707, "Project does not exist."));
            }

            var task = _meshContext.Tasks.FirstOrDefault(t => t.Id == request.taskId);

            if (task == null)
            {
                return(JsonReturnHelper.ErrorReturn(604, "Task does not exist."));
            }

            if (_permissionCheck.CheckProjectPermission(request.username, project) != PermissionCheckHelper.ProjectAdmin)
            {
                return(JsonReturnHelper.ErrorReturn(701, "Permission denied."));
            }

            var subTask = _meshContext.Subtasks.FirstOrDefault(s => s.TaskId == task.Id && s.Title == request.subTaskName);

            if (subTask != null)
            {
                return(JsonReturnHelper.ErrorReturn(608, "subTaskName already exists."));
            }

            var principalUser = _meshContext.Users.FirstOrDefault(u => u.Email == request.principal);

            if (principalUser == null)
            {
                return(JsonReturnHelper.ErrorReturn(603, "Principal does not exist."));
            }

            var newSubTask = new Subtask()
            {
                TaskId      = task.Id,
                Title       = request.subTaskName,
                Description = request.description
            };

            using (var transaction = _meshContext.Database.BeginTransaction())
            {
                try
                {
                    _meshContext.Subtasks.Add(newSubTask);
                    _meshContext.Assigns.Add(new Assign()
                    {
                        TaskId = newSubTask.TaskId,
                        Title  = newSubTask.Title,
                        UserId = principalUser.Id
                    });
                    _meshContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    _logger.LogError(e.ToString());
                    return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
                }
            }


            return(SubTaskResult(new SubTaskInfo()
            {
                TaskId = newSubTask.TaskId,
                CreatedTime = newSubTask.CreatedTime,
                Description = newSubTask.Description,
                Founder = user.Nickname,
                Title = newSubTask.Title,
                isFinished = newSubTask.Finished,
                Status = GetStatus(task.EndTime, newSubTask.Finished),
                Principal = GetSubTaskPrincipals(newSubTask.TaskId, newSubTask.Title)
            }));
        }