Beispiel #1
0
        // GET api/<controller>/5
        public ReferenceTaskViewModel Get(int id)
        {
            var taskInDb = _manager.FindTaskById(id);

            if (taskInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            ReferenceTaskViewModel model = new ReferenceTaskViewModel()
            {
                Id   = taskInDb.Id,
                Name = taskInDb.Name
            };


            return(model);
        }
Beispiel #2
0
        public ActionResult ViewProject(int id)
        {
            var project = _dataManager.FindProjectById(id);


            if (project == null)
            {
                return(HttpNotFound());
            }

            var userId         = HttpContext.User.Identity.GetUserId();
            var userAccessList = _dataManager.GetUserAccessOnProject(id);

            bool isOwner   = userId.Equals(project.OwnerId);
            bool hasAccess = userAccessList.Any(access => access.UserId.Equals(userId));

            if (!isOwner &&
                !hasAccess)
            {
                //TODO: Update to display error that the user does not have access to the project
                return(HttpNotFound());
            }

            List <ReferenceTaskViewModel> taskList = new List <ReferenceTaskViewModel>();

            foreach (var taskModel in project.TaskList)
            {
                if (taskModel.SprintId == null || taskModel.SprintId == 0)
                {
                    ReferenceTaskViewModel taskReference = new ReferenceTaskViewModel()
                    {
                        Id   = taskModel.Id,
                        Name = taskModel.Name
                    };
                    if (taskModel.Status.Equals(TaskState.Finished))
                    {
                        taskReference.IsCompleted = true;
                    }

                    taskList.Add(taskReference);
                }
            }

            List <SprintViewModel> sprintList = new List <SprintViewModel>();

            foreach (var sprintModel in project.SprintList)
            {
                SprintViewModel model = Mapper.Map <SprintViewModel>(sprintModel);

                int openTasks              = 0;
                int workingTask            = 0;
                int finishedTasks          = 0;
                int percentageOfCompletion = 0;
                try
                {
                    //TODO  see why what is the problem and why the respons is 0 0 0
                    model.Tasks.ForEach(task =>
                    {
                        TaskModel currentTask = project.TaskList.Find(taskModel => taskModel.Id == task.Id);

                        if (currentTask.Status != null)
                        {
                            if (currentTask.Status.Equals(TaskState.Open))
                            {
                                openTasks++;
                            }
                            else if (currentTask.Status.Equals(TaskState.Working) ||
                                     currentTask.Status.Equals(TaskState.Review))
                            {
                                workingTask++;
                            }
                            else if (currentTask.Status.Equals(TaskState.Finished))
                            {
                                task.IsCompleted = true;
                                finishedTasks++;
                            }
                        }
                    });
                    int totalNumberOfTasks = openTasks + workingTask + finishedTasks;
                    percentageOfCompletion = finishedTasks * 100 / totalNumberOfTasks;
                }
                catch
                {
                    Console.WriteLine("Failed to calculate  sprint task status for project " + project.Name);
                }

                model.OpenTasks              = openTasks;
                model.WorkingTasks           = workingTask;
                model.FinishedTasks          = finishedTasks;
                model.PercentageOfCompletion = percentageOfCompletion;

                sprintList.Add(model);
            }


            ProjectViewModel viewModel = new ProjectViewModel()
            {
                Name       = project.Name,
                Id         = project.Id,
                OwnerId    = project.OwnerId,
                TaskList   = taskList,
                SprintList = sprintList
            };


            return(View("ViewProject", viewModel));
        }