Example #1
0
        public IHttpActionResult Permissions([FromBody] PermissionsCustomerLoadModel permissions)
        {
            try
            {
                var processPermission = new ProcessPermission(null, _permissionsService, _mciRequestService, _logger, null);
                var message           = processPermission.AddOrUpdateCustomerPermission(permissions);
                return(Ok(message));
            }
            catch (Exception exception)
            {
                if (_logParameterValue)
                {
                    _logger.Error($"PermissionsLoad: ErrorTag: {ErrorTagProvider.ErrorTagDatabase} --  {exception.Message}");

                    _logger.Error(
                        $"Parameters MembershipLoad:- Name=FirstName={permissions.CustomerNameAndAddress.FirstName}, LastName={permissions.CustomerNameAndAddress.Surname}, Dob={permissions.CustomerNameAndAddress.Dob}, " +
                        $" Address=AddresLine1={ permissions.CustomerNameAndAddress.Address.Address1 ?? ""}, AddressLine2={permissions.CustomerNameAndAddress.Address.Address2 ?? ""}, AddressLine3={permissions.CustomerNameAndAddress.Address.Address3 ?? ""}, " +
                        $" AddressLine4={permissions.CustomerNameAndAddress.Address.Address4 ?? ""}, PostCode={permissions.CustomerNameAndAddress.Address.Postcode ?? ""}");
                }
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message)));
            }
        }
 internal static extern IntPtr OpenProcess(ProcessPermission processPermission, bool bInheritHandle, int processId);
        public object[] Execute(KeyValueParameter keyValue)
        {
            int processedObject = 0;

            _keyValue = keyValue;

            object[] output = new object[_keyValue.ResponseRequestedItems.Count];
            try
            {
                //if (_keyValue.ReturnMe.CustomerKeys != null)
                //{
                //    var customerKeyProcess = new CustomerKeyProcess(_keyValue, _mciRequestService,
                //        _clientScopeService, _logger);
                //    output[_processedObject] = customerKeyProcess.Process();
                //    _processedObject++;
                //}

                //if (_keyValue.ReturnMe.MailingHistory != null)
                //{
                //    MailingHistoryProcess mailingHistoryProcess = new MailingHistoryProcess(
                //        _nameAndAddress, _mailingHistoryService, _mciRequestService, _clientScopeService,
                //        _logger, _keyValue);
                //    output[_processedObject] = mailingHistoryProcess.ProcessForKeyValue();
                //    _processedObject++;
                //}

                if (_keyValue.ReturnMe.Permissions != null && _keyValue.ReturnMe.Permissions.Required)
                {
                    // we make some temporary parameters to pass so that we can create an address to construct
                    // the ProcessPermission() object

                    //KeyValueParameter tempKVP = new KeyValueParameter();
                    //tempKVP.KeyValue = _keyValue.KeyValue;
                    //tempKVP.AccessControl = new WebApiServices.Models.Security.AccessControl();
                    //tempKVP.AccessControl.CustomerKeyAccess.Add(new WebApiServices.Models.Security.CustomerKeyAccess() { HasAccess = true, Key = WebApiServices.Models.GroupCode.GCUST });
                    //tempKVP.AccessControl.ModuleAccess.Add(new WebApiServices.Models.Security.ModuleAccess() { HasAccess = true, Key = WebApiServices.Models.GroupCode.GCUST });
                    //tempKVP.ReturnMe.CustomerDetails.AddressType = AddressType.Correspondence;


                    //var customerDetails = new CustomerDetailsProcess(tempKVP, _customerDetailsService, _logger);
                    //WebApiServices.Models.Customer.CustomerInfoDetails details = customerDetails.Process() as WebApiServices.Models.Customer.CustomerInfoDetails;

                    NameAndAddressParameter tempNad = new NameAndAddressParameter();

                    tempNad.AccessControl          = _keyValue.AccessControl;
                    tempNad.ResponseRequestedItems = _keyValue.ResponseRequestedItems;
                    tempNad.ReturnMe       = _keyValue.ReturnMe;
                    tempNad.NameAndAddress = new WebApiServices.Models.NameAndAddress();



                    //if (details != null)
                    //{
                    //tempNad.NameAndAddress.FirstName = details.FirstName;
                    //tempNad.NameAndAddress.Surname = details.Surname;
                    //tempNad.NameAndAddress.Title = details.Title;
                    //tempNad.NameAndAddress.Dob = details.Dob;

                    //if (details.Address.GetType() == typeof(WebApiServices.Models.Customer.CorrespondenceAddress))
                    //{
                    //    WebApiServices.Models.Customer.CorrespondenceAddress a = details.Address as WebApiServices.Models.Customer.CorrespondenceAddress;

                    //    tempNad.NameAndAddress.Address.Address1 = a.Address1;
                    //    tempNad.NameAndAddress.Address.Address2 = a.Address2;
                    //    tempNad.NameAndAddress.Address.Address3 = a.Address3;
                    //    tempNad.NameAndAddress.Address.Address4 = a.Address4;
                    //    tempNad.NameAndAddress.Address.Postcode = a.Postcode;

                    //}
                    //else if(details.Address.GetType() == typeof(WebApiServices.Models.Customer.TransactionalAddress))
                    //{
                    //    WebApiServices.Models.Customer.TransactionalAddress a = details.Address as WebApiServices.Models.Customer.TransactionalAddress;

                    //    tempNad.NameAndAddress.Address = new Address()
                    //    {
                    //        Address1 = a.HouseNumber + (string.IsNullOrEmpty(a.HouseNumber) == false ? " " : "") + a.Street,
                    //        Address2 = a.Street1,
                    //        Address3 = a.City,
                    //        Address4 = a.County,
                    //        Postcode = a.Postcode
                    //    };

                    //}

                    //var permissionProcess = new ProcessPermission(_keyValue, _permissionService, _mciRequestService, _logger, _nameAndAddress);
                    var permissionProcess = new ProcessPermission(_keyValue, _permissionService, _mciRequestService, _logger, tempNad);
                    output[processedObject] = permissionProcess.ProcessPermissionFromKeyValue();
                    processedObject++;
                    // }
                }

                //if (_keyValue.ReturnMe.Membership != null && _keyValue.ReturnMe.Membership.Required)
                //{
                //    var membershipProcess = new MembershipProcess(_keyValue, _membershipService,
                //        _mciRequestService, _logger);
                //    var memberObj = membershipProcess.ProcessMembershipWithKeyValue();
                //    output[_processedObject] = memberObj;
                //    _processedObject++;
                //    if (memberObj != null && (memberObj.GetType() != typeof(NoAccessToMembership)))
                //    {
                //        //need to resize the array to accommodate the membershipstatus, membershipCancelReason and MembershipStatusReason values
                //        //that are retrieved from GMD to populate the frontend e.g AFE
                //        Array.Resize(ref output, output.Length + 1);
                //        output[_processedObject] = membershipProcess.GetMembershipOptionsData();
                //        _processedObject++;
                //    }
                //}

                //if (_keyValue.ReturnMe.CustomerDetails != null && _keyValue.ReturnMe.CustomerDetails.Required)
                //{
                //    CustomerInfo info = new CustomerInfo();
                //    var customerDetails = new CustomerDetailsProcess(_keyValue, _customerDetailsService,_logger);
                //    info.CustomerDetails = customerDetails.Process();
                //    output[_processedObject] = info;
                //    _processedObject++;
                //}

                //if (_keyValue.ReturnMe.TravelSummary != null && _keyValue.ReturnMe.TravelSummary.Required)
                //{
                //    var travelSummary = new CustomerMatchProcess(_nameAndAddress, _customerMatchService, _travelSummaryService, _logger);
                //    output[_processedObject] = travelSummary.TravelSummaryProcess(int.Parse(_keyValue.KeyValue.Value));
                //    _processedObject++;
                //}
            }
            catch (Exception ex)
            {
                _logger.Error($"{this.GetType().Name}: ErrorTag: {ErrorTagProvider.ErrorTag} -- {ex.Message}", ex);
                throw new Exception(ex.Message);
            }

            return(output);
        }
        public object[] Execute(NameAndAddressParameter nameAndAddress)
        {
            int processedObject = 0;

            _nameAndAddress = nameAndAddress;

            object[] output = new object[_nameAndAddress.ResponseRequestedItems.Count];
            try
            {
                foreach (var item in _nameAndAddress.ResponseRequestedItems)
                {
                    switch (item)
                    {
                    case ReturnMeTypeConstant.CustomerKeys:
                        //CustomerKeyProcess customerKeyProcess = new CustomerKeyProcess(_keyValue,
                        //    _mciRequestService, _clientScopeService, _logger, _nameAndAddress);
                        //output[processedObject] = customerKeyProcess.ProcessForNameAndAddress( _nameAndAddress, _keyValue );
                        //
                        output[processedObject] = _customerKeyProcess.ProcessForNameAndAddress(_nameAndAddress, _keyValue);
                        // AE Feb 18 : Use process from DI container

                        processedObject++;
                        break;

                    case ReturnMeTypeConstant.MailingHistory:
                        MailingHistoryProcess mailingHistoryProcess = new MailingHistoryProcess(_nameAndAddress,
                                                                                                _mailingHistoryService, _mciRequestService, _clientScopeService, _logger, _keyValue);
                        output[processedObject] = mailingHistoryProcess.Process();
                        processedObject++;
                        break;

                    case ReturnMeTypeConstant.Permissions:
                        var processPermission = new ProcessPermission(_keyValue, PermissionService,
                                                                      _mciRequestService, _logger, _nameAndAddress);
                        output[processedObject] = processPermission.ProcessPermissionForNameAndAddress();
                        processedObject++;
                        break;

                    case ReturnMeTypeConstant.Membership:

                        // GITCS-1 : Refactor to NameAndAddressStrategyMembershipReaderParts, in place of MembershipProcess class
                        //
                        var membershipDetailReader =
                            _nameAndAddressReaders[
                                NameAndAddressStrategyReaderImplementations.MembershipDetailsReaderPart];
                        var memberObj = membershipDetailReader.Process(_nameAndAddress,
                                                                       _keyValue?.KeyValue.IntValue);

                        /*
                         * var membershipProcess = new MembershipProcess(_keyValue, _membershipService,
                         *  _mciRequestService, _logger, _nameAndAddress);
                         * var memberObj = membershipProcess.GetMembershipFromNameAndAddress();
                         */

                        output[processedObject] = memberObj;
                        processedObject++;

                        if (memberObj != null && (memberObj.GetType() != typeof(NoAccessToMembership)))
                        {
                            //need to resize the array to accommodate the membershipstatus, membershipCancelReason and MembershipStatusReason values
                            //that are retrieved from GMD to populate the frontend e.g AFE
                            Array.Resize(ref output, output.Length + 1);
                            // output[processedObject] = membershipProcess.GetMembershipOptionsData();

                            //var membershipOptionsReader =
                            //    _nameAndAddressReaders[
                            //        NameAndAddressStrategyReaderImplementations.MembershipOptionsReaderPart ];
                            output[processedObject] = _membershipOptionsReader.Process(_nameAndAddress, null);

                            processedObject++;
                        }

                        break;

                    case ReturnMeTypeConstant.CustomerMatch:
                        var customerMatch          = new CustomerMatchProcess(_nameAndAddress, _customerMatchService, _travelSummaryService, _logger);
                        var matchedCustomerDetails = customerMatch.Process();
                        output[processedObject] = matchedCustomerDetails;
                        processedObject++;
                        break;

                    case ReturnMeTypeConstant.TravelSummary:
                        var travelSummary = new CustomerMatchProcess(_nameAndAddress, _customerMatchService, _travelSummaryService, _logger);
                        output[processedObject] = travelSummary.TravelSummaryProcess(0, _nameAndAddress.NameAndAddress);
                        processedObject++;
                        break;
                    }
                }
            }

            catch (Exception ex)
            {
                _logger.Error(
                    "NameAndAddressStrategy: " + "ErrorTag: " + ErrorTagProvider.ErrorTag + " -- " + ex.Message, ex);
                throw new Exception(ex.Message);
            }
            return(output);
        }
        public IHttpActionResult Post(PermissionsCustomerLoad permissions)
        {
            try
            {
                var mappedPermissions = Mapper.Map <WebApiServices.Models.Gdpr.PermissionsCustomerLoadModel>(permissions);
                var processPermission =
                    new ProcessPermission(null, _permissionsService, _mciRequestService, _logger, null);
                var message = processPermission.AddOrUpdateCustomerPermission(mappedPermissions);

                //Post show return summary instead of message if the load is successfully
                if (string.Compare(DatabaseMessage.PermissionsCreated, message,
                                   StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    if ((!string.IsNullOrWhiteSpace(permissions.CustomerNameAndAddress.FirstName)) &&
                        (!string.IsNullOrWhiteSpace(permissions.CustomerNameAndAddress.Surname)) &&
                        (permissions.CustomerNameAndAddress.Address != null))
                    {
                        NameAndAddressParameter parameter = new NameAndAddressParameter()
                        {
                            NameAndAddress = permissions.CustomerNameAndAddress, ResponseRequestedItems = new List <string>()
                            {
                                ReturnMeTypeConstant.Permissions.ToString()
                            }
                        };

                        parameter.ReturnMe = new ReturnMe()
                        {
                            Permissions = new ReturnMePermissions
                            {
                                Required            = true,
                                Journey             = permissions.JourneyType,
                                ResponseParameter   = GdprResponseType.Summary.ToString(),
                                PermissionParameter = "All",
                                MatchType           = Saga.Gmd.WebApiServices.Common.MatchType.POSTCODE_AND_NAME.ToString()
                            }
                        };
                        parameter.NameAndAddress.MatchType = Saga.Gmd.WebApiServices.Common.MatchType.POSTCODE_AND_NAME
                                                             .ToString();

                        // Use indexed DI resoloution to get the required strategy
                        IGetRequestProcess nameAndAddress = _strategyProcesses[GetRequestProcessImplementations.NameAndAddress];

                        //NameAndAddressStrategy nameAndAddress = new NameAndAddressStrategy(parameter,
                        //    _mailingHistoryService, _mciRequestService, _clientScopeService, _logger, _permissionsService,
                        //    _membershipService, _customerMatchService, _customerDetailsService, _travelSummaryService);
                        parameter.AccessControl =
                            _clientScopeService.VerifyUserHasAccessToGroupCode(parameter.AccessControl,
                                                                               Scope.CUSTOMER_PERMISSIONS_RETRIEVE_NAMEADDR);
                        object output = nameAndAddress.Execute(parameter);
                        return(Ok(output));
                    }
                    else
                    {
                        KeyValueParameter parameter = new KeyValueParameter()
                        {
                            ResponseRequestedItems = new List <string>()
                            {
                                ReturnMeTypeConstant.Permissions.ToString()
                            },
                            KeyValue = new KeyValue()
                            {
                                Key = "CPCK", Value = permissions.PermissionsId.ToString()
                            }
                        };

                        parameter.ReturnMe = new ReturnMeForKeyValuePair()
                        {
                            Permissions = new ReturnMePermissions
                            {
                                Required            = true,
                                Journey             = permissions.JourneyType,
                                ResponseParameter   = GdprResponseType.Summary.ToString(),
                                PermissionParameter = "All"
                            }
                        };

                        // Use indexed DI resoloution  to get the required strategy
                        IGetRequestProcess strategy = _strategyProcesses[GetRequestProcessImplementations.PermissionsKeyValuePair];

                        //PermissionsKeyValuePairStrategy strategy = new PermissionsKeyValuePairStrategy(parameter, _mailingHistoryService,
                        //    _mciRequestService, _clientScopeService,
                        //    _logger, _permissionsService,
                        //    _membershipService, _customerDetailsService,
                        //    _travelSummaryService, _customerMatchService);
                        object output = strategy.Execute(parameter);
                        return(Ok(output));
                    }
                }
                return(Ok(message));
            }
            catch (Exception exception)
            {
                if (_logParameterValue)
                {
                    _logger.Error($"PermissionGetNameAndAddress: ErrorTag: {ErrorTagProvider.ErrorTagDatabase} --  {exception.Message}");

                    _logger.Error(
                        $"Parameters PermissionLoad:- Name=FirstName={permissions.CustomerNameAndAddress.FirstName}, LastName={permissions.CustomerNameAndAddress.Surname}, Dob={permissions.CustomerNameAndAddress.Dob}, " +
                        $" Address=AddresLine1={ permissions.CustomerNameAndAddress.Address.Address1 ?? ""}, AddressLine2={permissions.CustomerNameAndAddress.Address.Address2 ?? ""}, AddressLine3={permissions.CustomerNameAndAddress.Address.Address3 ?? ""}, " +
                        $" AddressLine4={permissions.CustomerNameAndAddress.Address.Address4 ?? ""}, PostCode={permissions.CustomerNameAndAddress.Address.Postcode ?? ""}");
                }
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message)));
            }
        }