Exemplo n.º 1
0
        public async Task <ActionResult> ApplyApproval(TimeApprovalModel request)
        {
            var req = new TimeApprovalRequest(
                approvingUserId: await sessionAdapter.EmployeeIdAsync(),
                approvingUserIsAdmin: User.IsInRole(UserRoleName.Admin),
                employeeId: request.EmployeeId,
                weekId: request.WeekId,
                newApprovalState: request.NewApprovalState
                );
            var res = await approveTimeCommand.ApplyApproval(req);

            if (res.Successful)
            {
                NotificationsController.AddNotification(this.User.SafeUserName(), $"Timesheet is {request.NewApprovalState}");
                return(Ok());
            }
            else
            {
                NotificationsController.AddNotification(this.User.SafeUserName(), $"{string.Join(",",res.Errors)}");
                return(Unauthorized());
            }
        }
Exemplo 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 }));
        }