Пример #1
0
        public int?GetPersistantKey(NameAndAddress nameAndAddress)
        {
            CustomerMatchParameter param = new CustomerMatchParameter();

            param.FirstName = nameAndAddress.FirstName;
            param.Surname   = nameAndAddress.Surname;
            param.Dob       = nameAndAddress.Dob;
            param.Title     = nameAndAddress.Title;
            param.Email     = nameAndAddress.Email;
            param.Phone     = nameAndAddress.Phone;
            param.Address1  = nameAndAddress.Address.Address1;
            param.Address2  = nameAndAddress.Address.Address2;
            param.Address3  = nameAndAddress.Address.Address3;
            param.Address4  = nameAndAddress.Address.Address4;
            param.Postcode  = nameAndAddress.Address.Postcode;

            // GICTS-3 Customer Matching on first character : Don't set a default match type
            //
            param.MatchType = nameAndAddress.MatchType;

            // changed for ACSU-113 to use passed value or default to POSTCODE_AND_NAME

            /*
             * if (string.IsNullOrEmpty(param.MatchType) == true)
             * {
             *  // default to POSTCODE_AND_NAME
             *  param.MatchType = MatchType.POSTCODE_AND_NAME.ToString();
             * }
             * else
             * {
             *  param.MatchType = nameAndAddress.MatchType;
             * }
             */

            var matchedCustomers = _mailingHistoryDataAccess.GetMatchingCustomers(param).FirstOrDefault();

            return(matchedCustomers?.CustomerId);
        }
        public dynamic GetMailingHistoryList(Models.MailingHistory.MailingHistory mailingHistory = null, NameAndAddress nameAndAddress = null, IEnumerable <int> customerIdList = null)
        {
            CustomerMatchParameter parameter = new CustomerMatchParameter();

            if (nameAndAddress != null)
            {
                parameter.MatchType = "NAME_AND_ADDRESS";
                parameter.Address1  = nameAndAddress.Address.Address1;
                parameter.Address2  = nameAndAddress.Address.Address2;
                parameter.Address3  = nameAndAddress.Address.Address3;
                parameter.Address4  = nameAndAddress.Address.Address4;
                parameter.Postcode  = nameAndAddress.Address.Postcode;
                parameter.Dob       = nameAndAddress.Dob;
                parameter.Phone     = nameAndAddress.Phone;
                parameter.Email     = nameAndAddress.Email;
                parameter.FirstName = nameAndAddress.FirstName;
                parameter.Surname   = nameAndAddress.Surname;
                parameter.Title     = nameAndAddress.Title;
                if (mailingHistory != null)
                {
                    parameter.FromDate = mailingHistory.FromDate;
                    parameter.ToDate   = mailingHistory.ToDate;
                    parameter.Product  = mailingHistory.Product;
                }
            }

            List <ExpandoObject> expandoObject = new List <ExpandoObject>();

            try
            {
                List <MatchedCustomer> customerIds = new List <MatchedCustomer>();
                if (customerIdList == null)
                {
                    customerIds = _dataAccess.GetMatchingCustomers(parameter);
                }
                else
                {
                    foreach (var id in customerIdList)
                    {
                        customerIds.Add(new MatchedCustomer {
                            CustomerId = id
                        });
                    }
                }

                List <int> ids = new List <int>();

                foreach (var item in customerIds)
                {
                    ids.Add(item.CustomerId);
                }

                List <MailingHistoryResult> list = new List <MailingHistoryResult>();
                if (mailingHistory != null)
                {
                    list = _dataAccess.GetCustomerMailingHistory(null, ids, mailingHistory.Product,
                                                                 mailingHistory.FromDate, mailingHistory.ToDate, string.Empty);

                    if (mailingHistory.FieldsTobeReturned.Contains(null) || mailingHistory.FieldsTobeReturned.Count == 0)
                    {
                        return(list);
                    }
                }
                else
                {
                    list = _dataAccess.GetCustomerMailingHistory(null, ids, string.Empty,
                                                                 null, null, null);
                    return(list);
                }

                DataShapedObject dataShapedObject = new DataShapedObject();
                foreach (var item in list)
                {
                    if (mailingHistory.FieldsTobeReturned != null &&
                        mailingHistory.FieldsTobeReturned.Count != 0)
                    {
                        expandoObject.Add(dataShapedObject.Create(item, mailingHistory.FieldsTobeReturned));
                    }
                }
            }

            catch (Exception ex)
            {
                _logger.Info("MailingHistoryService.GetMailingHistoryList " + ex.Message, ex);
                throw new Exception(ex.Message);
            }

            return(expandoObject);
        }