Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(string taskItemId, string taskSubitemId, TaskSubitemModel taskSubitemModel)
        {
            ViewBag.TaskItemId = taskItemId;
            var accessToken = Session["MicrosoftAccessToken"] as string;
            TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken);

            try
            {
                // TODO: Add update logic here
                TaskSubitem taskSubitem = GetTaskSubitemFromModel(taskItemId, taskSubitemModel);
                taskSubitem.Id = taskSubitemId;

                if (taskSubitem.IsCompleted ||
                    taskSubitem.TaskStatusId.Equals(((int)TaskStatusEnum.Completed).ToString()))
                {
                    taskSubitem.TaskStatusId = ((int)TaskStatusEnum.Completed).ToString();
                    taskSubitem.IsCompleted  = true;
                }

                await taskSubitemService.UpdateTaskSubitem(taskSubitem);

                var allTaskSubitems = await taskSubitemService.GetTaskSubitems(taskItemId);

                if (allTaskSubitems.All(t => t.IsCompleted))
                {
                    var taskItemService = new TaskItemService(accessToken);
                    var taskItem        = await taskItemService.GetTaskItemById(taskItemId);

                    taskItem.IsCompleted  = true;
                    taskItem.TaskStatusId = ((int)TaskStatusEnum.Completed).ToString();
                    await taskItemService.UpdateTaskItem(taskItem);
                }

                return(RedirectToAction("Index", new { taskItemId }));
            }

            catch
            {
                return(View(taskSubitemModel));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GetPieChart(string fromDatePie, string toDatePie)
        {
            string      accessToken        = Session["MicrosoftAccessToken"] as string;
            var         taskSubItemService = new TaskSubitemService(accessToken);
            UserService userService        = new UserService(accessToken);
            var         userId             = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft);

            DateTime fromDate = DateTime.Parse(fromDatePie);
            DateTime toDate   = DateTime.Parse(toDatePie);
            var      taskSubitemsCompleted = await taskSubItemService.GetCompletedTaskSubitems(userId, fromDate, toDate);

            var taskSubitemsNotCompleted = await taskSubItemService.GetNotCompletedTaskSubitems(userId, fromDate, toDate);

            int    width      = 600;
            int    height     = 50;
            string chartTitle = "You don not have any tasks in this period of time";

            if (taskSubitemsCompleted.Any() || taskSubitemsNotCompleted.Any())
            {
                width      = 1024;
                height     = 700;
                chartTitle = "Your completed and not completed tasks";
            }

            var key = new Chart(width: width, height: height)
                      .AddSeries(
                chartType: "pie",
                legend: "Completed/NotCompleted",
                xValue:
                new[]
            {
                "Completed: " + taskSubitemsCompleted.Count,
                "Not completed: " + taskSubitemsNotCompleted.Count
            },
                yValues: new[] { taskSubitemsCompleted.Count, taskSubitemsNotCompleted.Count }).AddTitle(chartTitle)
                      .Write();

            return(null);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Delete(string taskItemId, string taskSubitemId, TaskSubitemModel taskSubitemModel)
        {
            var accessToken = Session["MicrosoftAccessToken"] as string;

            try
            {
                // TODO: Add delete logic here
                TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken);
                TaskSubitem        taskSubitem        = await taskSubitemService.GetTaskSubitemById(taskSubitemId);

                taskSubitem.IsDeleted = true;

                await taskSubitemService.UpdateTaskSubitem(taskSubitem);

                return(RedirectToAction("Index", new { taskItemId }));
            }

            catch
            {
                return(View());
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(string taskItemId, TaskSubitemModel taskSubitemModel)
        {
            ViewBag.TaskItemId = taskItemId;
            string accessToken = Session["MicrosoftAccessToken"] as string;

            try
            {
                var taskSubitem = GetTaskSubitemFromModel(taskItemId, taskSubitemModel);
                taskSubitem.Id = Guid.NewGuid().ToString();
                TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken);
                await taskSubitemService.InsertTaskSubitem(taskSubitem);

                // TODO: Add insert logic here

                return(RedirectToAction("Index", new { taskItemId }));
            }

            catch
            {
                return(View());
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> GetPieChart(string fromDatePie, string toDatePie)
        {
            string      accessToken        = Session["MicrosoftAccessToken"] as string;
            var         taskSubItemService = new TaskSubitemService(accessToken);
            UserService userService        = new UserService(accessToken);
            var         userId             = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft);

            DateTime fromDate = DateTime.Parse(fromDatePie);
            DateTime toDate   = DateTime.Parse(toDatePie);
            var      taskSubitemsCompleted = await taskSubItemService.GetCompletedTaskSubitems(userId, fromDate, toDate);

            var taskSubitemsNotCompleted = await taskSubItemService.GetNotCompletedTaskSubitems(userId, fromDate, toDate);

            var key = new Chart(width: 1280, height: 720)
                      .AddSeries(
                chartType: "pie",
                legend: "Completed/NotCompleted",
                xValue: new[] { "Completed: " + taskSubitemsCompleted.Count, "Not completed: " + taskSubitemsNotCompleted.Count },
                yValues: new[] { taskSubitemsCompleted.Count, taskSubitemsNotCompleted.Count })
                      .Write();

            return(null);
        }
Ejemplo n.º 6
0
        // GET: TaskSubitem/Delete/5
        public async Task <ActionResult> Delete(string taskItemId, string taskSubitemId)
        {
            ViewBag.TaskItemId = taskItemId;

            var accessToken = Session["MicrosoftAccessToken"] as string;
            TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken);
            TaskSubitem        taskSubitem        = await taskSubitemService.GetTaskSubitemById(taskSubitemId);

            TaskSubitemModel taskSubitemModel = GetTaskSubitemModel(taskSubitem);

            var statuses = await taskSubitemService.GetAvailableTaskStatuses();

            taskSubitemModel.Status = statuses.Single(s => s.Id == taskSubitem.TaskStatusId).Status;

            //ViewBag.StatusID = new SelectList(statuses, "Id", "Status", status.Id);

            var tasks = new ObservableCollection <TaskSubitem>()
            {
                new TaskSubitem()
            };
            var items = await taskSubitemService.GetTaskSubitems(taskItemId);

            if (!String.IsNullOrWhiteSpace(taskSubitem.PredecessorId))
            {
                taskSubitemModel.Predecessor = await taskSubitemService.GetTaskSubitemNameByTaskSubitemId(taskSubitem.PredecessorId);
            }
            else
            {
                taskSubitemModel.Predecessor = "";
            }
            if (!String.IsNullOrWhiteSpace(taskSubitem.SuccessorId))
            {
                taskSubitemModel.Successor =
                    await taskSubitemService.GetTaskSubitemNameByTaskSubitemId(taskSubitem.SuccessorId);
            }
            else
            {
                taskSubitemModel.Successor = "";
            }



            UserService userService = new UserService(accessToken);

            if (!String.IsNullOrWhiteSpace(taskSubitem.ExecutorId))
            {
                taskSubitemModel.Executor = (await userService.GetUserById(taskSubitem.ExecutorId)).FullName;
            }
            else
            {
                taskSubitemModel.Executor = "";
            }

            if (await AccessAdmin(taskItemId))
            {
                return(View(taskSubitemModel));
            }
            else
            {
                return(View("AccessDenied"));
            }
        }
Ejemplo n.º 7
0
        // GET: TaskSubitem/Edit/5
        public async Task <ActionResult> Edit(string taskItemId, string taskSubitemId)
        {
            ViewBag.TaskItemId = taskItemId;
            string             accessToken        = Session["MicrosoftAccessToken"] as string;
            TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken);
            TaskSubitem        taskSubitemInfo    = await taskSubitemService.GetTaskSubitemById(taskSubitemId);

            TaskSubitemModel taskSubitemModel = GetTaskSubitemModel(taskSubitemInfo);

            var statuses = await taskSubitemService.GetAvailableTaskStatuses();

            var status = statuses.Single(s => s.Id == taskSubitemInfo.TaskStatusId);

            ViewBag.StatusID = new SelectList(statuses, "Id", "Status", status.Id);

            var tasks = new ObservableCollection <TaskSubitem>()
            {
                new TaskSubitem()
            };
            var items = await taskSubitemService.GetTaskSubitems(taskItemId);

            items.ForEach(i => tasks.Add(i));

            if (String.IsNullOrWhiteSpace(taskSubitemInfo.PredecessorId))
            {
                ViewBag.PredecessorID = new SelectList(tasks, "Id", "Name", new TaskSubitem());
            }
            else
            {
                ViewBag.PredecessorID = new SelectList(tasks, "Id", "Name", taskSubitemInfo.PredecessorId);
            }

            if (String.IsNullOrWhiteSpace(taskSubitemInfo.SuccessorId))
            {
                ViewBag.SuccessorID = new SelectList(tasks, "Id", "Name", new TaskSubitem());
            }
            else
            {
                ViewBag.SuccessorID = new SelectList(tasks, "Id", "Name", taskSubitemInfo.SuccessorId);
            }

            UserService      userService     = new UserService(accessToken);
            TaskItemService  taskItemService = new TaskItemService(accessToken);
            UserGroupService userGroup       = new UserGroupService(accessToken);

            var itemInfo = await taskItemService.GetTaskItemById(taskItemId);

            var groupInfo = await userGroup.GetUserGroupTableForGroup(itemInfo.GroupId);

            var         userInGroup = groupInfo.Select(u => u.UserId);
            List <User> userProp    = new List <User>();

            userProp.Add(new User());
            foreach (var usrId in userInGroup)
            {
                var user = await userService.GetUserById(usrId);

                userProp.Add(user);
            }

            var userInternalId = await userService.GetUserInternalId(Session["UserId"] as string, UserDomainEnum.Microsoft);

            //var defaultExecutor = userProp.Single(i => i.Id == userInternalId);

            if (String.IsNullOrWhiteSpace(taskSubitemInfo.ExecutorId))
            {
                ViewBag.ExecutorID = new SelectList(userProp, "Id", "FullName", new TaskSubitem());
            }
            else
            {
                ViewBag.ExecutorID = new SelectList(userProp, "Id", "FullName", taskSubitemInfo.ExecutorId);
            }

            if (await AccessAdmin(taskItemId))
            {
                return(View(taskSubitemModel));
            }
            else if (await AccessEditor(taskItemId))
            {
                return(View(taskSubitemModel));
            }
            else
            {
                return(View("AccessDenied"));
            }
        }