Ejemplo n.º 1
0
        private void AddTask(WorkTask task, Guid userId)
        {
            var project = context.Projects.FirstOrDefault(p => p.Name.Equals(task.ProjectName));

            task.Project = project;
            task.UserId  = userId;

            context.Tasks.Add(task);
            context.SaveChanges();
            if (task.Started.HasValue && task.Finished.HasValue)
            {
                context.TaskHistory.Add(new TaskHistoryItem {
                    Task = task, Status = TaskStatus.InProgress, Created = task.Started
                });
                context.TaskHistory.Add(new TaskHistoryItem {
                    Task = task, Status = TaskStatus.Closed, Created = task.Finished
                });
            }
            if (task.Status.Equals(TaskStatus.InProgress))
            {
                context.TaskHistory.Add(new TaskHistoryItem {
                    Task = task, Status = TaskStatus.InProgress, Created = DateTime.Now
                });
            }
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        private void UpdateTask(WorkTask task)
        {
            var dbEntry = context.Tasks
                          .Include(e => e.TaskHistoryItems)
                          .FirstOrDefault(t => t.Id == task.Id);

            if (dbEntry == null)
            {
                return;
            }

            var isChanged = false;

            if (!string.IsNullOrWhiteSpace(task.Name) && (dbEntry.Name == null || !dbEntry.Name.Equals(task.Name)))
            {
                dbEntry.Name = task.Name;
                isChanged    = true;
            }
            if (!string.IsNullOrWhiteSpace(task.Description) && (dbEntry.Description == null || !dbEntry.Description.Equals(task.Description)))
            {
                dbEntry.Description = task.Description;
                isChanged           = true;
            }
            if (!string.IsNullOrWhiteSpace(task.Comment) && (dbEntry.Comment == null || !dbEntry.Comment.Equals(task.Comment)))
            {
                dbEntry.Comment = task.Comment;
                isChanged       = true;
            }
            if (!dbEntry.Priority.Equals(task.Estimate))
            {
                dbEntry.Priority = task.Priority;
                isChanged        = true;
            }
            if (!dbEntry.Estimate.Equals(task.Estimate))
            {
                dbEntry.Estimate = task.Estimate;
                isChanged        = true;
            }
            if (!dbEntry.Status.Equals(task.Status))
            {
                if (dbEntry.Equals(TaskStatus.Stopped) && task.Status.Equals(TaskStatus.Closed))
                {
                    var taskHistoryItem = task.LastHistoryItem;
                    taskHistoryItem.Status = TaskStatus.Closed;
                }
                else
                {
                    context.TaskHistory.Add(new TaskHistoryItem {
                        Task = task, Status = task.Status, Created = DateTime.Now
                    });
                }
                isChanged = true;
            }

            if (isChanged)
            {
                task.Modified = DateTime.Now;
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 public void SaveTask(WorkTask task, Guid userId)
 {
     if (task.Id == new Guid())
     {
         AddTask(task, userId);
     }
     else
     {
         UpdateTask(task);
     }
 }