コード例 #1
0
            /// <summary>
            /// Validates whether the shift can be resumed.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <param name="shift">The shift.</param>
            private void ValidateCanUseShift(UseShiftRequest request, Shift shift)
            {
                if (shift == null)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, "There is no shift with the given identifier.");
                }

                var staffId = this.Context.GetPrincipal().UserId;

                if (!this.Context.GetPrincipal().IsInRole(AuthenticationHelper.ManagerPrivilegies))
                {
                    EmployeePermissions employeePermission = EmployeePermissionHelper.GetEmployeePermissions(this.Context, staffId);

                    if (employeePermission != null && (!(string.Equals(shift.StaffId, staffId) || string.Equals(shift.CurrentStaffId, staffId)) && ((shift.IsShared && !employeePermission.AllowUseSharedShift) || (!shift.IsShared && !employeePermission.AllowMultipleShiftLogOn))))
                    {
                        throw new UserAuthorizationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_UseExistingShiftPermissionDenied, string.Format(CultureInfo.CurrentUICulture, "Permission denied to use the existing shift: {0}", this.Context.GetPrincipal().UserId));
                    }
                }

                if (shift.Status != ShiftStatus.Open)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidRequest, "Only open shifts can be used. If the shift is suspended, try resuming instead.");
                }
                else if (!string.Equals(shift.CurrentTerminalId, request.TerminalId, StringComparison.OrdinalIgnoreCase) && !shift.IsShared)
                {
                    // we can only use an open shift on a different terminal if it is a shared shift
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftAlreadyOpenOnDifferentTerminal, "The shift is open on a different terminal.");
                }
            }
コード例 #2
0
            /// <summary>
            /// Executes the create shift staging workflow.
            /// </summary>
            /// <param name="request">The new Shift request.</param>
            /// <returns>The new Shift response.</returns>
            protected override ChangeShiftStatusResponse Process(ChangeShiftStatusRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShiftTerminalId, "request.ShiftTerminalId");

                if (this.Context.GetTerminal() != null)
                {
                    request.TerminalId = this.Context.GetTerminal().TerminalId;
                }

                EmployeePermissions permissions = EmployeePermissionHelper.GetEmployeePermissions(this.Context, this.Context.GetPrincipal().UserId);
                bool includeSharedShifts        = permissions.HasManagerPrivileges || permissions.AllowManageSharedShift || permissions.AllowUseSharedShift;
                var  staffId    = this.Context.GetPrincipal().UserId;
                var  terminalId = request.ShiftTerminalId;
                var  shifts     = ShiftDataDataServiceHelper.GetShifts(
                    this.Context,
                    this.Context.GetPrincipal().ChannelId,
                    terminalId,
                    request.ShiftId,
                    includeSharedShifts);

                Shift shift = ShiftDataDataServiceHelper.FilterShifts(shifts, terminalId, staffId).FirstOrDefault();

                if (shift == null)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, "There is no shift with the given identifier.");
                }

                ShiftTransitionHelper shiftTransitionHelper = new ShiftTransitionHelper(this.Context, request);

                // Validate if the change of shift status can be performed
                shiftTransitionHelper.TransitShiftStatus(shift);

                shift.StatusDateTime = this.Context.GetNowInChannelTimeZone();

                UpdateShiftStagingTableDataRequest dataServiceRequest = new UpdateShiftStagingTableDataRequest(shift);

                request.RequestContext.Runtime.Execute <NullResponse>(dataServiceRequest, this.Context);

                this.SaveTransactionLog(shift, request.TransactionId);

                if (request.ToStatus == ShiftStatus.Closed)
                {
                    this.PurgeSalesTransactionData(request.RequestContext);
                }

                return(new ChangeShiftStatusResponse(shift));
            }
コード例 #3
0
            /// <summary>
            /// Validates whether a status transition is possible on the specified shift.
            /// </summary>
            /// <param name="shift">The shift.</param>
            private void ValidateCanChangeStatus(Shift shift)
            {
                bool isManager = this.context.GetPrincipal().IsInRole(AuthenticationHelper.ManagerPrivilegies);

                if (shift.Status == ShiftStatus.Open &&
                    !string.Equals(shift.TerminalId, this.request.TerminalId, StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(shift.CurrentTerminalId, this.request.TerminalId, StringComparison.OrdinalIgnoreCase))
                {
                    if (shift.IsShared)
                    {
                        if (!isManager)
                        {
                            EmployeePermissions employeePermission = EmployeePermissionHelper.GetEmployeePermissions(this.context, this.context.GetPrincipal().UserId);
                            if (!employeePermission.AllowManageSharedShift)
                            {
                                throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_EmployeeNotAllowedManageSharedShift, "Employee not allowed to manage shared shift.");
                            }
                        }
                    }
                    else
                    {
                        throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftAlreadyOpenOnDifferentTerminal, "The shift is open on a different terminal.");
                    }
                }

                if (!isManager)
                {
                    if (shift.IsShared)
                    {
                        EmployeePermissions employeePermission = EmployeePermissionHelper.GetEmployeePermissions(this.context, this.context.GetPrincipal().UserId);
                        if (!employeePermission.AllowManageSharedShift)
                        {
                            throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_EmployeeNotAllowedManageSharedShift, "Employee not allowed to manage shared shift.");
                        }
                    }

                    // Get the original user id for manager override cases.
                    string userId = (!string.IsNullOrWhiteSpace(this.context.GetPrincipal().OriginalUserId) && this.context.GetPrincipal().UserId != this.context.GetPrincipal().OriginalUserId) ? this.context.GetPrincipal().OriginalUserId : this.context.GetPrincipal().UserId;
                    if (!string.Equals(shift.StaffId, userId, StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(shift.CurrentStaffId, userId, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidRequest, "The user does not have permission to change shift status.");
                    }
                }
            }
コード例 #4
0
            /// <summary>
            /// Validates whether employee can open shifts.
            /// </summary>
            /// <param name="request">The create shift request.</param>
            private void ValidateCanOpenShift(CreateShiftRequest request)
            {
                IList <Shift> shifts = ShiftDataDataServiceHelper.GetAllStoreShiftsWithStatus(this.Context, this.Context.GetPrincipal().ChannelId, ShiftStatus.Open, new QueryResultSettings(PagingInfo.AllRecords), true);

                if (!this.Context.GetPrincipal().IsInRole(AuthenticationHelper.ManagerPrivilegies))
                {
                    EmployeePermissions employeePermission = EmployeePermissionHelper.GetEmployeePermissions(this.Context, this.Context.GetPrincipal().UserId);
                    if (employeePermission != null && employeePermission.AllowMultipleLogins == false && shifts.Any(shift => (string.Equals(shift.StaffId, this.Context.GetPrincipal().UserId, StringComparison.OrdinalIgnoreCase) || string.Equals(shift.CurrentStaffId, this.Context.GetPrincipal().UserId, StringComparison.OrdinalIgnoreCase))))
                    {
                        throw new UserAuthorizationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_OpenMultipleShiftsNotAllowed, string.Format(CultureInfo.CurrentUICulture, "Permission denied to open multiple shifts: {0}", this.Context.GetPrincipal().UserId));
                    }

                    if (request.IsShared)
                    {
                        if (!employeePermission.AllowManageSharedShift)
                        {
                            throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_EmployeeNotAllowedManageSharedShift, "Employee not allowed to manage shared shift.");
                        }
                    }
                }

                // Validate if shift is already open with given shift identifier.
                if (request.ShiftId != null && shifts.Any(shift => shift.ShiftId == request.ShiftId && string.Equals(shift.TerminalId, request.TerminalId, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new DataValidationException(
                              DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_TerminalHasAnOpenShift,
                              string.Format("There is already an open shift with shift id {0} on the current terminal.", request.ShiftId));
                }

                // Validate if any shift is open for the cash drawer specified in request.
                bool cannotOpenShift = shifts.Any(shift =>
                {
                    bool cashDrawerHasOpenShift = string.Equals(shift.CashDrawer, request.CashDrawer, StringComparison.OrdinalIgnoreCase);
                    return(cashDrawerHasOpenShift && (shift.IsShared || string.Equals(shift.CurrentTerminalId, request.TerminalId, StringComparison.OrdinalIgnoreCase)));
                });

                if (cannotOpenShift)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CashDrawerHasAnOpenShift, "There is an open shift on the current cash drawer.");
                }
            }
コード例 #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            ModelBinders.Binders.Add(typeof(DateTime), new CustomDateBinder());
            ModelBinders.Binders.Add(typeof(DateTime?), new NullableCustomDateBinder());

            Stream stream = new MemoryStream(StrToByteArray(Resources.Licence));

            stream.Position = 0;
            Aspose.Pdf.License     licensePdf     = new Aspose.Pdf.License();
            Aspose.Words.License   licenseWords   = new Aspose.Words.License();
            Aspose.Cells.License   licenseCells   = new Aspose.Cells.License();
            Aspose.Slides.License  licenseSlides  = new Aspose.Slides.License();
            Aspose.BarCode.License licenseBarCode = new Aspose.BarCode.License();

            licensePdf.SetLicense(stream);
            stream.Position = 0;
            licenseWords.SetLicense(stream);
            stream.Position = 0;
            licenseCells.SetLicense(stream);
            stream.Position = 0;
            licenseSlides.SetLicense(stream);
            stream.Position = 0;
            licenseBarCode.SetLicense(stream);
            stream.Close();
            //   CreateLogins();

            //	CheckLogins();

            LogHelper.InitLogger();
            LogHelper.Log.Info("Application Start");

            EmployeePermissionHelper.Init();


            QScheduler.Start();
        }
コード例 #6
0
            /// <summary>
            /// Workflow to process employee time clock activities.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The response.</returns>
            protected override EmployeeTimeRegistrationResponse Process(EmployeeTimeRegistrationRequest request)
            {
                ThrowIf.Null(request, "request");
                EmployeeTimeRegistrationResponse response;

                if (request.IsLatestActivity && request.IsSelectStore)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidRequest, "Both latest activity and selecting from stores is not supported");
                }

                bool enableTimeRegistration = EmployeeTimeRegistrationWorkflowHelper.ValidateTimeRegistrationFunctionalityProfile(this.Context);

                if (!enableTimeRegistration)
                {
                    throw new DataValidationException(
                              DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_TimeClockNotEnabled,
                              string.Format("Time Clock should be enabled before performing employee activities. EmployeeActivityType: {0}", request.EmployeeActivityType));
                }

                // This flag is set to true if client needs to retrieve the latest activity of the employee.
                if (request.IsLatestActivity)
                {
                    EmployeeActivity employeeActivity = this.GetLatestEmployeeActivity();

                    response = new EmployeeTimeRegistrationResponse(new[] { employeeActivity }.AsPagedResult());

                    return(response);
                }

                // The workflow follows any one of the activity chosen from client.
                switch (request.EmployeeActivityType)
                {
                case EmployeeActivityType.ClockIn:
                {
                    var currentActivityDateTimeOffset = this.ProcessClockIn();
                    response = new EmployeeTimeRegistrationResponse(currentActivityDateTimeOffset);
                    break;
                }

                case EmployeeActivityType.ClockOut:
                {
                    var currentActivityDateTimeOffset = this.ProcessClockOut();
                    response = new EmployeeTimeRegistrationResponse(currentActivityDateTimeOffset);
                    break;
                }

                case EmployeeActivityType.BreakFromWork:
                {
                    var currentActivityDateTimeOffset = this.ProcessBreakFlow(EmployeeTimeRegistrationWorkflowHelper.BreakFromWork);
                    response = new EmployeeTimeRegistrationResponse(currentActivityDateTimeOffset);
                    break;
                }

                case EmployeeActivityType.BreakForLunch:
                {
                    var currentActivityDateTimeOffset = this.ProcessBreakFlow(EmployeeTimeRegistrationWorkflowHelper.BreakForLunch);
                    response = new EmployeeTimeRegistrationResponse(currentActivityDateTimeOffset);
                    break;
                }

                case EmployeeActivityType.Logbook:
                {
                    if (request.IsManagerLogbook)
                    {
                        EmployeePermissions employeePermisssion = EmployeePermissionHelper.GetEmployeePermissions(this.Context, this.Context.GetPrincipal().UserId);

                        if (employeePermisssion == null || !employeePermisssion.AllowViewTimeClockEntries)
                        {
                            throw new DataValidationException(
                                      DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ViewTimeClockNotEnabled,
                                      string.Format("View Time Clock Entries should be enabled to view other employee activities. EmployeeActivityType: {0}", request.EmployeeActivityType));
                        }

                        var employeeActivities = this.ProcessManagerLogBook(request.EmployeeActivitySearchCriteria, request.QueryResultSettings.Paging, request.QueryResultSettings.Sorting);
                        response = new EmployeeTimeRegistrationResponse(employeeActivities.AsPagedResult());
                    }
                    else
                    {
                        var employeeActivities = this.ProcessEmployeeLogBook(request.EmployeeActivitySearchCriteria, request.QueryResultSettings.Paging, request.QueryResultSettings.Sorting);
                        response = new EmployeeTimeRegistrationResponse(employeeActivities.AsPagedResult());
                    }

                    break;
                }

                default:
                    throw new DataValidationException(
                              DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_UnSupportedType,
                              string.Format("Unsupported type for Employee Activity {0}", request.EmployeeActivityType));
                }

                return(response);
            }
コード例 #7
0
ファイル: ConnectionCache.cs プロジェクト: ncelsRS/ncelsRepo
        private bool IsAllow(Guid employeeId, string key)
        {
            var permission = EmployeePermissionHelper.IsVisibility(key, employeeId);

            return(permission);
        }
コード例 #8
0
            /// <summary>
            /// Executes the workflow to get available Shifts.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The response.</returns>
            protected override GetAvailableShiftsResponse Process(GetAvailableShiftsRequest request)
            {
                ThrowIf.Null(request, "request");

                IEnumerable <Shift> shifts;
                EmployeePermissions employeePermission = EmployeePermissionHelper.GetEmployeePermissions(this.Context, this.Context.GetPrincipal().UserId);

                var staffId = this.Context.GetPrincipal().UserId;

                GetCurrentTerminalIdDataRequest dataRequest = new GetCurrentTerminalIdDataRequest();
                string terminalId = this.Context.Execute <SingleEntityDataServiceResponse <string> >(dataRequest).Entity;

                bool isManager = this.Context.GetPrincipal().IsInRole(AuthenticationHelper.ManagerPrivilegies);
                bool readAllShifts;
                bool includeSharedShifts;

                switch (request.Status)
                {
                case ShiftStatus.Suspended:
                case ShiftStatus.BlindClosed:
                    includeSharedShifts = employeePermission.AllowManageSharedShift;

                    // If user is manager or has permission to logon multiple shifts or allowed to manage shared shifts)
                    // Read all shifts including shared
                    // Else read only shifts that belong to the user and are not shared shifts.
                    if (isManager || (employeePermission.AllowMultipleShiftLogOn && includeSharedShifts))
                    {
                        // Read all shifts
                        shifts = ShiftDataDataServiceHelper.GetAllStoreShiftsWithStatus(this.Context, this.Context.GetPrincipal().ChannelId, request.Status, request.QueryResultSettings, true);
                    }
                    else if (employeePermission.AllowMultipleShiftLogOn && !includeSharedShifts)
                    {
                        shifts = ShiftDataDataServiceHelper.GetShiftsForStaffWithStatus(this.Context, this.Context.GetPrincipal().ChannelId, request.Status, request.QueryResultSettings, false);
                    }
                    else if (includeSharedShifts && !employeePermission.AllowMultipleShiftLogOn)
                    {
                        var allShifts = ShiftDataDataServiceHelper.GetShiftsForStaffWithStatus(this.Context, this.Context.GetPrincipal().ChannelId, request.Status, request.QueryResultSettings, true);

                        // Exclude non shared shifts and shift not opened or used by the current staff id.
                        shifts = allShifts.Where(s => (s.IsShared == true || s.CurrentStaffId == staffId || s.StaffId == staffId));
                    }
                    else
                    {
                        shifts = ShiftDataDataServiceHelper.GetShiftsForStaffWithStatus(this.Context, this.Context.GetPrincipal().ChannelId, staffId, request.Status, request.QueryResultSettings, false);
                    }

                    break;

                case ShiftStatus.Open:

                    includeSharedShifts = employeePermission.AllowManageSharedShift || employeePermission.AllowUseSharedShift;
                    readAllShifts       = isManager || (includeSharedShifts && employeePermission.AllowMultipleShiftLogOn);

                    // If user is manager or (has permission to logon multiple shifts and allowed to manage or use shared shifts)
                    // Read all terminal shifts including shared
                    // Else read only shifts that belong to the user and are not shared shifts.
                    if (readAllShifts)
                    {
                        var openShiftsOnTerminal    = ShiftDataDataServiceHelper.GetAllOpenedShiftsOnTerminal(this.Context, this.Context.GetPrincipal().ChannelId, terminalId, false);
                        var openSharedShiftsOnStore = ShiftDataDataServiceHelper.GetAllOpenedSharedShiftsOnStore(this.Context, this.Context.GetPrincipal().ChannelId);
                        shifts = openShiftsOnTerminal.Union(openSharedShiftsOnStore);
                    }
                    else
                    {
                        IEnumerable <Shift> usableShifts;
                        if (employeePermission.AllowMultipleShiftLogOn)
                        {
                            usableShifts = ShiftDataDataServiceHelper.GetAllOpenedShiftsOnTerminal(this.Context, this.Context.GetPrincipal().ChannelId, terminalId, false);
                        }
                        else
                        {
                            usableShifts = ShiftDataDataServiceHelper.GetOpenedShiftsOnTerminalForStaff(this.Context, this.Context.GetPrincipal().ChannelId, staffId, terminalId, false);
                        }

                        if (includeSharedShifts)
                        {
                            var openSharedShiftsOnStore = ShiftDataDataServiceHelper.GetAllOpenedSharedShiftsOnStore(this.Context, this.Context.GetPrincipal().ChannelId);
                            shifts = usableShifts.Union(openSharedShiftsOnStore);
                        }
                        else
                        {
                            shifts = usableShifts;
                        }
                    }

                    break;

                default:
                    shifts = new Shift[] { };
                    break;
                }

                if (shifts != null || shifts.Count() != 0)
                {
                    shifts = ShiftDataDataServiceHelper.FilterShifts(shifts, terminalId, staffId);
                }

                return(new GetAvailableShiftsResponse(shifts.AsPagedResult()));
            }