Ejemplo n.º 1
0
        public List <HostessReward> GetHostessRewards(int customerID, int partyID = 0, List <Party> parties = null)
        {
            if (parties == null)
            {
                parties = new List <Party>();
            }

            List <HostessReward> rewards = new List <HostessReward>();

            try
            {
                // If we are not passing parties in, we need to go and get the party or parties that are needed for this call
                if (parties.Count() == 0)
                {
                    var searchRequest = new PartySearchRequest();

                    searchRequest.CustomerID = customerID;

                    if (partyID > 0)
                    {
                        searchRequest.PartyID = partyID;
                    }

                    parties = SearchParties(searchRequest);
                }

                // Add out qualifications
                parties.ForEach(party =>
                {
                    var matchingQualification = HostessRewardQualifications.Where(q => q.SalesTotal < party.CurrentSales).OrderByDescending(q => q.SalesTotal).FirstOrDefault();

                    if (matchingQualification != null)
                    {
                        matchingQualification.PartyID = party.PartyID;

                        // Here we resolve the Amount Discount vs. Percent off logic
                        if (matchingQualification.FreeProductAmount == 0 && matchingQualification.FreeProductPercentage > 0)
                        {
                            var partyTotal = party.CurrentSales;

                            matchingQualification.FreeProductAmount = matchingQualification.FreeProductPercentage * partyTotal;
                        }

                        rewards.Add(matchingQualification);
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error Getting Hostess Rewards: {Message}", ex.Message);
            }

            return(rewards);
        }
Ejemplo n.º 2
0
        public List <Party> SearchParties(PartySearchRequest request)
        {
            var list = new List <Party>();

            try
            {
                var whereClause = "";

                if (request.FirstName.IsNotNullOrEmpty())
                {
                    whereClause = "where c.FirstName = '{0}'".FormatWith(request.FirstName);
                }

                if (request.LastName.IsNotNullOrEmpty())
                {
                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " c.LastName = '{0}'".FormatWith(request.LastName);
                }

                if (request.ZipCode.IsNotNullOrEmpty())
                {
                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " p.ZipCode = '{0}'".FormatWith(request.ZipCode);
                }

                // We filter this one with a year, month and day comparison only to not filter out specific times the user sets when creating the party - Mike M.
                if (request.EventStart != null)
                {
                    var partyStartDate = Convert.ToDateTime(request.EventStart);

                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " p.EventStart = '{0}'".FormatWith(partyStartDate);

                    //query = query.Where(p => p.StartDate.Year == partyStartDate.Year && p.StartDate.Month == partyStartDate.Month && p.StartDate.Day == partyStartDate.Day);
                }

                if (request.ShowOpenPartiesOnly)
                {
                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " p.PartyStatusID = {0}".FormatWith(PartyStatusTypes.Open);
                }

                if (request.PartyID > 0)
                {
                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " p.PartyID = {0}".FormatWith(request.PartyID);
                }

                if (request.CustomerID > 0)
                {
                    if (whereClause.Length > 0)
                    {
                        whereClause += " and ";
                    }
                    else
                    {
                        whereClause = "where ";
                    }
                    whereClause += " p.DistributorID = {0}".FormatWith(request.CustomerID);
                }

                using (var context = ExigoDAL.Sql())
                {
                    list = context.Query <Party>(@"
                            select
                            p.*,
                            CurrentSales = case when p.Field1 <> '' then p.Field1 else 0 end,
                            HostID = c.CustomerID,
                            HostFirstName = c.FirstName,
                            HostLastName = c.LastName,
                            HostPhone = coalesce(c.Phone, c.MobilePhone)
                            from Parties p
                            left join Customers c 
                                on p.HostID = c.CustomerID
                            " + whereClause).ToList();
                }

                // Run a method on each party so it will populate the Address property correctly
                list.ForEach(p => { p.PopulateAddress(); });
            }
            catch (Exception ex)
            {
                throw new Exception("PartyService.SearchParties failed: " + ex.Message);
            }

            return(list);
        }