Beispiel #1
0
 public User GetTaskWorker(Task task)
 {
     if (task.WorkerId == null)
     {
         return null;
     }
     return GetContext().User.SingleOrDefault(w => w.Id == task.WorkerId);
 }
Beispiel #2
0
        public void CreateTask(string name)
        {
            Task task = new Task
            {
                Name = name,
                Date = DateTime.Now
            };

            _taskRepository.AddTask(task);
        }
Beispiel #3
0
        public void CheckEmailSending(Task oldTask, Task newTask)
        {
            if (oldTask.State == (byte)TaskState.Open)
            {
                // Task was open
                if (newTask.State != (byte)TaskState.Open)
                {
                    // Now task has user
                    SendEmail(NewTaskEmailSubject, String.Format(NewTaskMessageTemplate, newTask.Name.Quote()),
                        _userBlo.GetUser(newTask.WorkerId.Value).Email);
                }
                return;
            }

            if (oldTask.WorkerId == newTask.WorkerId)
            {
                // Task' user remained the same
                StringBuilder message = new StringBuilder();

                if (oldTask.Name.Trim() != newTask.Name.Trim())
                {
                    message.Append(String.Format(TaskNameChangedMessageTemplate, oldTask.Name.Quote(),
                        newTask.Name.Quote()));
                }

                if (oldTask.Content.Trim() != newTask.Content.Trim())
                {
                    message.Append(String.Format(TaskContentChangedMessageTemplate, oldTask.Name.Quote(),
                        newTask.Content.Quote()));
                }

                if (oldTask.State != newTask.State)
                {
                    message.Append(String.Format(TaskStateChangedMessageTemplate, oldTask.Name.Quote(),
                        ((TaskState) newTask.State).ToString().Quote()));
                }

                if (message.Length != 0)
                {
                    SendEmail(TaskChangedEmailSubject, message.ToString(),
                        _userBlo.GetUser(newTask.WorkerId.Value).Email);
                }
                return;
            }

            // Task' user was changed

            // Notify old worker
            SendEmail(TaskCanceledEmailSubject, String.Format(TaskCanceledMessageTemplate, oldTask.Name.Quote()),
                _userBlo.GetUser(oldTask.WorkerId.Value).Email);

            // Notify new worker
            SendEmail(NewTaskEmailSubject, String.Format(NewTaskMessageTemplate, newTask.Name.Quote()),
                _userBlo.GetUser(newTask.WorkerId.Value).Email);
        }
Beispiel #4
0
        public void SaveManagerTask(int id, string name, string content, byte state, int workerId)
        {
            Task newTask = new Task
            {
                Id = id,
                Name = name,
                Content = content,
                State = state,
                WorkerId = workerId == -1 ? (int?) null : workerId
            };

            _emailService.CheckEmailSending(GetTask(id), newTask);

            _taskRepository.SaveManagerTask(id, name, content, state, workerId);
        }
Beispiel #5
0
        private UserModel GetUserModel(Task task)
        {
            if (task.State == 0)
            {
                // Task is open and has no workers
                return null;
            }

            User worker = _taskBlo.GetTaskWorker(task);
            return new UserModel
            {
                FullName = worker.First_Name + " " + worker.Last_Name,
                Id = worker.Id,
                Username = worker.Username
            };
        }
Beispiel #6
0
 /// <summary>
 /// Fills task model properties except collections - FreeWorkers and StateOptions
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 private TaskModel GetTaskModel(Task task)
 {
     return new TaskModel
     {
         Name = task.Name,
         Id = task.Id,
         State = task.State,
         Content = task.Content,
         Percentage = task.Percentage,
         Date = task.Date.ToString(CultureInfo.CurrentCulture),
         Worker = GetUserModel(task),
         IsAssigned = (TaskState)task.State != TaskState.Open
     };
 }
Beispiel #7
0
 public void AddTask(Task task)
 {
     TaskOperatorEntities context = GetContext();
     context.Task.Add(task);
     context.SaveChanges();
 }
Beispiel #8
0
 public User GetTaskWorker(Task task)
 {
     return _taskRepository.GetTaskWorker(task);
 }
Beispiel #9
0
 public void CheckEmailSending(Task oldTask, int newPercentage)
 {
 }