private void CreateMissngHostSpecials(CustomerExtendedResponse eventCustomerEx) { //Create Host Special if one does not exist in CustEx table var hostSpecial = RewardService.GetHostSpecialReward(Convert.ToDateTime(eventCustomerEx.Field2)); if (!string.IsNullOrWhiteSpace(hostSpecial.ItemCode)) { var details = RewardService.GetHostSpecialReward(eventCustomerEx.CustomerID); if (string.IsNullOrWhiteSpace(details.ItemCode)) //Create the host special entry in CustomerEx { var updateCustomerExtendedRequest = new UpdateCustomerExtendedRequest() { CustomerID = eventCustomerEx.CustomerID, CustomerExtendedID = eventCustomerEx.CustomerExtendedID, ExtendedGroupID = eventCustomerEx.ExtendedGroupID, Field8 = hostSpecial.ItemCode, Field9 = hostSpecial.DiscountAmount.ToString(CultureInfo.InvariantCulture), Field10 = string.Empty, // Reward Not Redeemed Field11 = hostSpecial.SalesThreshold.ToString(CultureInfo.InvariantCulture) }; Api.UpdateCustomerExtended(updateCustomerExtendedRequest); } } }
private Event ApiGetEventDetails(int eventId) { // TODO: Fix this hack. Dependency injection is no longer working on AJAX calls? if (null == Api) { Api = ExigoService.Exigo.WebService(); } var eventCustomerResponse = Api.GetCustomers(new GetCustomersRequest { CustomerID = eventId, CustomerTypes = new int[] { (int)CustomerTypes.Party } }); Customer eventCustomer = null; if (null != eventCustomerResponse && null != eventCustomerResponse.Customers && 0 != eventCustomerResponse.Customers.Length) { eventCustomer = Mapper.Map <Customer>(eventCustomerResponse.Customers[0]); } else { throw new ApplicationException("The provided event ID does not exist."); } var eventCustomerSiteResponse = Api.GetCustomerSite(new GetCustomerSiteRequest { CustomerID = eventId }); if (ResultStatus.Failure.Equals(eventCustomerSiteResponse.Result.Status)) { throw new ApplicationException("There an error while retrieving the details of the event ID provided."); } var eventCustomerExResponse = Api.GetCustomerExtended(new GetCustomerExtendedRequest { CustomerID = eventId, ExtendedGroupID = (int)CustomerExtendedGroup.PartyDetails, // Party Extended Fields }); CustomerExtendedResponse eventCustomerEx = null; if (ResultStatus.Success.Equals(eventCustomerExResponse.Result.Status) && null != eventCustomerExResponse.Items && 0 != eventCustomerExResponse.Items.Length) { eventCustomerEx = eventCustomerExResponse.Items[0]; } else { throw new ApplicationException("There an error while retrieving the details of the event ID provided."); } GetCustomersResponse creatorCustomerResponse = null; int creatorCustomerId = 0; if (int.TryParse(eventCustomerEx.Field5, out creatorCustomerId)) { creatorCustomerResponse = Api.GetCustomers(new GetCustomersRequest { CustomerID = creatorCustomerId, CustomerTypes = new int[] { (int)CustomerTypes.IndependentStyleAmbassador } }); } Customer creator = null; if (ResultStatus.Success.Equals(creatorCustomerResponse.Result.Status) && null != creatorCustomerResponse.Customers && 0 != creatorCustomerResponse.Customers.Length) { creator = Mapper.Map <Customer>(creatorCustomerResponse.Customers[0]); try { var creatorCustomerSiteResponse = Api.GetCustomerSite(new GetCustomerSiteRequest { CustomerID = creator.CustomerID }); creator.WebAlias = creatorCustomerSiteResponse.WebAlias; } catch { } } GetCustomersResponse hostCustomerResponse = null; int hostCustomerId = 0; if (int.TryParse(eventCustomerEx.Field6, out hostCustomerId)) { hostCustomerResponse = Api.GetCustomers(new GetCustomersRequest { CustomerID = hostCustomerId }); } Customer host = null; if (ResultStatus.Success.Equals(hostCustomerResponse.Result.Status) && null != hostCustomerResponse.Customers && 0 != hostCustomerResponse.Customers.Length) { host = Mapper.Map <Customer>(hostCustomerResponse.Customers[0]); } // Retrieve the party sales total var salesTotal = GetPointAccountBalance(eventId, PointAccounts.PartySalesTotal); // Retieve the Host' rewards point accounts var pointAccounts = GetHostRewardPointAccounts(eventId); //var bookingRewards = GetBookingRewards(); //int bookingRewardsOwnerId = 0; //int.TryParse(eventCustomerEx.Field7, out bookingRewardsOwnerId); // Create Missing Host Specials CreateMissngHostSpecials(eventCustomerEx); var @event = new Event() { Id = eventCustomer.CustomerID, Name = eventCustomer.FirstName, Location = eventCustomer.MainAddress, MainAddress1 = eventCustomer.MainAddress.Address1, MainAddress2 = eventCustomer.MainAddress.Address2, MainCity = eventCustomer.MainAddress.City, MainState = eventCustomer.MainAddress.State, MainZip = eventCustomer.MainAddress.Zip, MainCountry = eventCustomer.MainAddress.Country, Creator = creator, Host = host, IsNewGT = true, HostFullName = host.FirstName + " " + host.LastName, CreatorFullName = creator.FirstName + " " + creator.LastName, HostId = host.CustomerID.ToString(), HostEmail = host.Email, HostPhone = host.Phone, CreatorId = creator.CustomerID.ToString(), TotalSales = salesTotal, EventPointAccounts = null != pointAccounts?pointAccounts.ToArray() : null, //EventBookingRewards = bookingRewards, //BookingRewardsOwnerId = bookingRewardsOwnerId, WebAlias = eventCustomerSiteResponse.WebAlias, StartDate = Convert.ToDateTime(eventCustomerEx.Field1), ActualDate = Convert.ToDateTime(eventCustomerEx.Field2), EventStatus = eventCustomer.CustomerStatusID == 0 ? "Close" : Convert.ToDateTime(eventCustomerEx.Field4) < DateTime.Now ? "Close" : "Open", CloseDate = Convert.ToDateTime(eventCustomerEx.Field3), LockoutDate = Convert.ToDateTime(eventCustomerEx.Field4), PartyDate = string.IsNullOrEmpty(eventCustomerEx.Field12) ? Convert.ToDateTime(eventCustomerEx.Field2) : Convert.ToDateTime(eventCustomerEx.Field12), PartyStartTime = string.IsNullOrEmpty(eventCustomerEx.Field13) ? DateTime.Parse(eventCustomerEx.Field2) : DateTime.Parse(eventCustomerEx.Field13), PartyEndTime = string.IsNullOrEmpty(eventCustomerEx.Field14) ? DateTime.Parse(eventCustomerEx.Field2).AddHours(1) : DateTime.Parse(eventCustomerEx.Field14), TimeZone = string.IsNullOrEmpty(eventCustomerEx.Field15) ? "(UTC-06:00) Central Time (US & Canada)" : eventCustomerEx.Field15, DeletedEvents = eventCustomer.CustomerStatusID == 0 ? true : false, HostSpecialReward = (HostSpecialDiscount)eventCustomerEx, }; if ((@event.LockoutDate - @event.CloseDate).TotalDays <= 2.00) { @event.LockoutDate = @event.CloseDate.AddDays(7); } return(@event); }