示例#1
0
        private static void UpdateStatus(int dealId, int duration, string startDate, string startTime)
        {
            try
            {
                IPigDealRepository pigdealRepo = new PigDealRepository();

                // Is deal in future
                var dealStarts = Convert.ToDateTime(string.Format("{0} {1}", (startDate), startTime));
                var dealExpires = Convert.ToDateTime(string.Format("{0} {1}", (startDate), startTime)).AddHours(duration);

                if (dealStarts > DateTime.Now)
                {
                    //Update status to pending
                    pigdealRepo.UpdateStatus(dealId, "Pending");



                }
                else if (dealStarts < DateTime.Now && DateTime.Now < dealExpires)
                {
                    //Update status to active
                    pigdealRepo.UpdateStatus(dealId, "Active");


                }

                else
                {
                    //Update status to expired
                    pigdealRepo.UpdateStatus(dealId, "Expired");


                }

            }
            catch (Exception)
            {
                //LOG
                throw;
            }
            

        }
示例#2
0
        public static void ExpireDeals()
        {
            try
            {
                IPigDealRepository pigdealRepo = new PigDealRepository();

                var activeDealsQuery = from allDeals in pigdealRepo.GetDeals().Where(a => a.Status != "Expire")
                                       select allDeals;

                foreach (Deal deal in activeDealsQuery)
                {
                    UpdateStatus(deal.DealId, int.Parse(deal.Duration), deal.StartDate, deal.StartTime);
                }
            }
            catch (Exception)
            {
                
                //LOG
                throw;
            }
           

        }