Exemple #1
0
        public PartialViewResult SaveManagerTask(TaskModel taskModel)
        {
            ValidateTaskModel(taskModel);

            if (ModelState.IsValid)
            {
                _taskBlo.SaveManagerTask(taskModel.Id, taskModel.Name, taskModel.Content,
                         taskModel.State, taskModel.Worker.Id);
            }

            FillCollections(taskModel);

            return PartialView("_ManagerTask", taskModel);
        }
Exemple #2
0
 private void ValidateTaskModel(TaskModel taskModel)
 {
     if ((TaskState)taskModel.State == TaskState.Open && taskModel.Worker.Id != NoUserId)
     {
         ModelState.AddModelError("StateString", "State cannot be 'open' because task is assigned to worker");
         return;
     }
     if (taskModel.Worker.Id == NoUserId && (TaskState)taskModel.State != TaskState.Open)
     {
         ModelState.AddModelError("StateString", "State must be 'open' because task has no workers");
         return;
     }
     if (taskModel.Worker.Id != NoUserId && !_taskBlo.IsWorker(taskModel.Worker.Id, taskModel.Id) &&
         !_userBlo.IsFreeWorker(taskModel.Worker.Id))
     {
         ModelState.AddModelError("Worker", "Selected worker is busy");
     }
 }
Exemple #3
0
 private void FillCollections(TaskModel model)
 {
     model.WorkerOptions = GetWorkerOptions(model);
     model.StateOptions = GetStateOptions();
 }
Exemple #4
0
        private IEnumerable<SelectListItem> GetWorkerOptions(TaskModel model)
        {
            List<SelectListItem> workerOtions = new List<SelectListItem>();
            workerOtions.AddRange(_userBlo.GetFreeWorkers().Select(w => new SelectListItem {Text = w.Username, Value = w.Id.ToString()}));

            SelectListItem noUserItem = new SelectListItem { Text = NoUserString, Value = NoUserId.ToString() };

            if (model.Worker == null || model.Worker.Id == NoUserId)
            {
                // Task is open and has no workers
                noUserItem.Selected = true;
            }
            else if ((TaskState)model.State != TaskState.Complete || !_userBlo.IsFreeWorker(model.Worker.Id))
            {
                User dbUser = _userBlo.GetUser(model.Worker.Id);
                workerOtions.Add(new SelectListItem {Text = dbUser.Username, Value = dbUser.Id.ToString(), Selected = true});
            }

            workerOtions.Add(noUserItem);

            return workerOtions;
        }
Exemple #5
0
        public PartialViewResult SaveWorkerTask(TaskModel taskModel)
        {
            if (ModelState.IsValid)
            {
                _taskBlo.SetPercentage(taskModel.Id, taskModel.Percentage);
            }

            taskModel = GetTaskModel(_taskBlo.GetTask(taskModel.Id));

            return PartialView("_WorkerTask", taskModel);
        }