Ejemplo n.º 1
0
        public ActionResult Edit(TaskView view)
        {
            if (ModelState.IsValid)
            {
                using (ITransaction trans = DbSession.BeginTransaction())
                {
                    Task task = null;
                    if (view.Id.HasValue)
                    {
                        task = LoadEntity <Task>(view.Id.Value);
                    }
                    else
                    {
                        task = new Task();
                        task.SetStatus(TaskStatus.Created);
                        GetEntity <Call>(view.Call_Id).AddTask(task);
                    }

                    task = ModelMapper.Map <TaskView, Task>(view, task);
                    task.SetStatus(view.Status);

                    if (view.Executor_Id.HasValue)
                    {
                        task.Executor = LoadEntity <User>(view.Executor_Id.Value);
                    }

                    DbSession.SaveOrUpdate(task);
                    trans.Commit();

                    ShowedTasksType showedTasks = task.Status == TaskStatus.Completed || task.Status == TaskStatus.Checked ? ShowedTasksType.Completed : ShowedTasksType.Active;
                    return(RedirectToAction("Index", "Tasks", new { call = view.Call_Id, showedTasks = showedTasks }));
                }
            }
            return(View(view));
        }
Ejemplo n.º 2
0
        private TaskStatus[] GetStatusesForShow(ShowedTasksType showedTasks)
        {
            switch (showedTasks)
            {
            case ShowedTasksType.Active:
                return(ActiveTaskStatus);

            case ShowedTasksType.Completed:
                return(CompletedTaskStatus);

            default:
                return(new TaskStatus[] { });
            }
        }
Ejemplo n.º 3
0
        public ActionResult Index(int call, ShowedTasksType showedTasks = ShowedTasksType.All, int page = 1)
        {
            Call obj = GetEntity <Call>(call);

            ViewBag.ShowedTasksType = showedTasks;
            ViewBag.CallId          = obj.Id;
            ViewBag.ProjectId       = obj.Project.Id;
            return(View(new PageableData <Task>(DbSession, page, null, criteria =>
            {
                criteria.Add(Expression.Eq("Call", obj));
                TaskStatus[] statuses = GetStatusesForShow(showedTasks);
                if (statuses.Length > 0)
                {
                    criteria.Add(Expression.In("Status", statuses));
                }
            })));
        }