Esempio n. 1
0
        public async Task <IActionResult> Index([FromRoute(Name = "week-id")] int weekid,
                                                [FromRoute(Name = "employee-id")] int employeeId,
                                                [FromRoute(Name = "job-id")] int jobId,
                                                [FromRoute(Name = "task-id")] int taskId)
        {
            var currentUserId = await _sessionAdapter.EmployeeIdAsync();

            if (!User.IsInRole(UserRoleName.Admin) && employeeId != currentUserId)
            {
                var msg = "You are not allowed to edit another users effort selection.";
                return(CreateErrorResponse(msg));
            }

            var removeResult = await _removeRowCommand.RemoveRow(employeeId, weekid, taskId, jobId);

            if (removeResult.Successful)
            {
                NotificationsController.AddNotification(User.SafeUserName(), "The selected effort was removed.");
                return(new ObjectResult(new ApiResult <string>()
                {
                    Data = "The selected effort was removed."
                })
                {
                    StatusCode = StatusCodes.Status200OK
                });
            }
            else
            {
                return(CreateErrorResponse(string.Join(", ", removeResult.Errors)));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> Save(int weekId, int employeeId, FullTimeEntryViewModel vm, string postType)
        {
            var currentUserId = await sessionAdapter.EmployeeIdAsync();

            if (!User.IsInRole(UserRoleName.Admin) && employeeId != currentUserId)
            {
                return(RedirectToAction("Index", new { weekId }));
            }

            if (postType == "Save" || postType == "Add Task" || postType == "Submit")
            {
                var res = await saveTimeEntriesCommand.SaveTimeEntriesAsync(employeeId, weekId, vm);

                if (res.Successful)
                {
                    NotificationsController.AddNotification(User.SafeUserName(), "Timesheet has been saved");
                }
                else
                {
                    return(await ReloadPageForErrorCorrection(weekId, employeeId, vm, res));
                }
            }

            if (postType == "Add Task")
            {
                var AddResult = await addNewJobTaskComboCommand.AddNewJobTaskCombo(employeeId, weekId, vm.NewEntry.SelectedTaskId ?? 0, vm.NewEntry.SelectedJobId ?? 0);

                if (AddResult.Successful)
                {
                    NotificationsController.AddNotification(User.SafeUserName(), "The selected task has been added.");
                }
                else
                {
                    NotificationsController.AddNotification(User.SafeUserName(), "Select task could not be added.");
                    return(await ReloadPageForErrorCorrection(weekId, employeeId, vm, AddResult));
                }
            }

            if (postType == "Copy Job/Tasks From Previous Week")
            {
                await copyPreviousWeekTimeCommand.CopyPreviousWeekTime(employeeId, weekId);
            }

            if (postType == "Submit")
            {
                var req = new TimeApprovalRequest(
                    approvingUserId: await sessionAdapter.EmployeeIdAsync(),
                    approvingUserIsAdmin: User.IsInRole(UserRoleName.Admin),
                    employeeId: employeeId,
                    newApprovalState: TimeApprovalStatus.Submitted,
                    weekId: weekId
                    );
                var res = await approveTimeCommand.ApplyApproval(req);

                NotificationsController.AddNotification(User.SafeUserName(), $"Timesheet is {TimeApprovalStatus.Submitted}");
            }

            if (postType == "Approve")
            {
                var req = new TimeApprovalRequest(
                    approvingUserId: await sessionAdapter.EmployeeIdAsync(),
                    approvingUserIsAdmin: User.IsInRole(UserRoleName.Admin),
                    employeeId: employeeId,
                    newApprovalState: TimeApprovalStatus.Approved,
                    weekId: weekId
                    );
                var res = await approveTimeCommand.ApplyApproval(req);

                NotificationsController.AddNotification(User.SafeUserName(), $"Timesheet is {TimeApprovalStatus.Submitted}");
            }

            if (postType == "Reject")
            {
                var req = new TimeApprovalRequest(
                    approvingUserId: await sessionAdapter.EmployeeIdAsync(),
                    approvingUserIsAdmin: User.IsInRole(UserRoleName.Admin),
                    employeeId: employeeId,
                    newApprovalState: TimeApprovalStatus.Rejected,
                    weekId: weekId
                    );
                var res = await approveTimeCommand.ApplyApproval(req);

                NotificationsController.AddNotification(User.SafeUserName(), $"Timesheet is {TimeApprovalStatus.Rejected}");
            }
            if (postType == "Save New Combination")
            {
                var rowId     = vm.SelectedRowId;
                var oldJobId  = int.Parse(rowId.Substring(0, rowId.IndexOf(".")));
                var oldTaskId = int.Parse(rowId.Substring(rowId.IndexOf(".") + 1));
                var res       = await modifyJobTaskComboCommand.ModifyJobTaskCombo(employeeId, weekId, vm.NewEntry.SelectedTaskId ?? 0, vm.NewEntry.SelectedJobId ?? 0, oldTaskId, oldJobId);
            }

            if (postType == "RemoveRow")
            {
                var rowId  = vm.SelectedRowId;
                var jobId  = rowId.Substring(0, rowId.IndexOf("."));
                var taskId = rowId.Substring(rowId.IndexOf(".") + 1);
                var res    = await removeRowCommand.RemoveRow(employeeId, weekId, int.Parse(taskId), int.Parse(jobId));
            }
            return(RedirectToAction(nameof(Edit), new { weekId = weekId, employeeId = employeeId }));
        }