Esempio n. 1
0
        public async Task <IActionResult> Index([FromBody] NewEffort effort, [FromRoute(Name = "week-id")] int weekid, [FromRoute(Name = "employee-id")] int employeeId)
        {
            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 addResult = await _addNewJobTaskComboCommand.AddNewJobTaskCombo(employeeId, weekid, effort.SelectedTaskId, effort.SelectedJobId);

            if (addResult.Successful)
            {
                NotificationsController.AddNotification(User.SafeUserName(), "The selected task has been added.");
                return(new StatusCodeResult(StatusCodes.Status201Created));
            }
            else
            {
                return(CreateErrorResponse(string.Join(", ", addResult.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 }));
        }