Ejemplo n.º 1
0
        //GetBidWatchForUser
        public List <UserBidWatch> GetBidWatchForUser(long user_id, long event_id)
        {
            DataCacheObject     dco    = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.WATCHLISTS, "GETBIDWATCHFORUSER", new object[] { user_id, event_id }, CachingExpirationTime.Seconds_15);
            List <UserBidWatch> result = CacheRepository.Get(dco) as List <UserBidWatch>;

            if (result != null && result.Any())
            {
                return(result);
            }
            dataContext.CommandTimeout = 600000;
            result = (from p in dataContext.spBid_View_BidWatch(user_id, event_id)
                      select new UserBidWatch
            {
                AuctionStatus = p.AuctionStatus.GetValueOrDefault(1),
                Amount = p.Amount.GetValueOrDefault(0),
                CurrentBid = p.CurrentBid.GetValueOrDefault(0),
                HighBidder = p.HighBidder,
                Quantity = p.Quantity,
                Bids = p.Bids.GetValueOrDefault(0),
                MaxBid = p.MaxBid.GetValueOrDefault(0),
                Option = p.IsWatch.GetValueOrDefault(0),
                LinkParams = new LinkParams {
                    ID = p.Auction_ID, Lot = p.Lot.GetValueOrDefault(0), Title = p.Title, EventTitle = p.EventTitle, CategoryTitle = p.CategoryTitle, MainCategoryTitle = p.MainCategoryTitle
                }
            }).ToList();
            if (result.Any())
            {
                dco.Data = result;
                CacheRepository.Add(dco);
            }
            return(result);
        }
Ejemplo n.º 2
0
        //SendAfterClosingEmails
        public JsonExecuteResult SendAfterClosingEmails(long event_id)
        {
            bool iserror = false;

            try
            {
                Event evnt = GetEvent(event_id);
                if (evnt == null)
                {
                    return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database."));
                }
                if (evnt.CloseStep != 2)
                {
                    throw new Exception("This event is not closed");
                }

                EndOfAuction  eoa;
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Emails already sent to users:");
                dataContext.CommandTimeout = 6000000;
                foreach (var user in dataContext.spUser_GetBiddersForEventClose(event_id).ToList())
                {
                    try
                    {
                        eoa            = new EndOfAuction();
                        eoa.EventTitle = evnt.Title;
                        eoa.UserName   = String.Format("{0} {1}{2}", user.FirstName, String.IsNullOrEmpty(user.MiddleName) ? String.Empty : user.MiddleName + " ", user.LastName);
                        eoa.Invoices.AddRange(
                            (from p in dataContext.spInvoice_Detail_UserUnpaid(user.ID, event_id)
                             where p.Event_ID == event_id
                             select new InvoiceDetail
                        {
                            Auction_ID = p.Auction_ID,
                            Cost = p.Cost,
                            Invoice_ID = p.Invoice_ID,
                            LateFee = p.LateFee,
                            LinkParams =
                                new LinkParams
                            {
                                ID = p.Auction_ID,
                                Lot = p.Lot.GetValueOrDefault(0),
                                Title = p.Title,
                                Event_ID = p.Event_ID,
                                EventTitle = p.EventTitle,
                                EventCategory_ID = p.EventCategory_ID,
                                CategoryTitle = p.Category
                            },
                            Lot = p.Lot.GetValueOrDefault(0),
                            SaleDate = p.DateCreated,
                            Shipping = p.Shipping,
                            Tax = p.Tax,
                            Title = p.Title,
                            UserInvoice_ID = p.UserInvoices_ID.GetValueOrDefault(0)
                        }).ToList());

                        eoa.LoserLots.AddRange((from p in dataContext.spBid_View_BidWatch(user.ID, event_id)
                                                where p.IsWatch.GetValueOrDefault(0) == 0
                                                select new UserBidWatch
                        {
                            Amount = p.Amount.GetValueOrDefault(0),
                            Quantity = p.Quantity,
                            MaxBid = p.MaxBid.GetValueOrDefault(0),
                            Option = p.IsWatch.GetValueOrDefault(0),
                            LinkParams =
                                new LinkParams
                            {
                                ID = p.Auction_ID,
                                Lot = p.Lot.GetValueOrDefault(0),
                                Title = p.Title,
                                EventTitle = p.EventTitle,
                                CategoryTitle = p.CategoryTitle
                            },
                            Bids = p.Bids.GetValueOrDefault(0),
                            CurrentBid = p.CurrentBid.GetValueOrDefault(0),
                            HighBidder = p.HighBidder
                        }).ToList());
                        Mail.SendEndOfAuctionHTMLLetter(user.Email, eoa);
                        sb.AppendLine(user.Email);
                    }
                    catch (Exception ex)
                    {
                        iserror = true;
                        Logger.LogException("Winner email to user " + user.Login + " failed : " + ex.Message + " (" + ex.StackTrace + ")", ex);
                    }
                }
                Logger.LogInfo(sb.ToString());


                //Event current = GetEvent(event_id);
                //if (current == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database.");
                //if (current.CloseStep != 2) throw new Exception("This event is not closed");

                //List<Auction> allAuctions = (
                //  from A in dataContext.Auctions
                //  where A.Event_ID == current.ID && A.Status == (byte)Consts.AuctionStatus.Closed && A.Bids.Count > 0
                //  orderby A.Lot.Value ascending
                //  select A).ToList();

                //User user;
                //sp_GetAuctionWinnerTableResult bid;
                //List<sp_GetAuctionWinnerTableResult> bids;
                //foreach (Auction auc in allAuctions)
                //{
                //  bid = dataContext.sp_GetAuctionWinnerTable(auc.ID, 1).FirstOrDefault();

                //  user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID);
                //  if ((auc.Reserve.HasValue && auc.Reserve.Value > bid.Amount) || (user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue;

                //  if (user == null || !user.IsRecievingLotClosedNotice || String.IsNullOrEmpty(user.Email)) continue;
                //  try
                //  {
                //    Mail.SendWinningLetter(user.AddressCard_Billing.FirstName, user.AddressCard_Billing.LastName, user.Email, (long)auc.Lot.Value, auc.Title, bid.Amount.GetCurrency());
                //  }
                //  catch (Exception ex)
                //  {
                //    Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message);
                //  }

                //  if (auc.Bids.Count == 1) continue;

                //  bids = dataContext.sp_GetAuctionWinnerTable(auc.ID, 0).ToList();
                //  foreach (var winbid in bids)
                //  {
                //    bid = winbid;
                //    user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID);

                //    if ((user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue;
                //    if (user == null || !user.IsRecievingLotSoldNotice || String.IsNullOrEmpty(user.Email)) continue;
                //    try
                //    {
                //      Mail.SendEndOfAuctionLetter(user.Email, (long)auc.Lot.Value, auc.Title);
                //    }
                //    catch (Exception ex)
                //    {
                //      Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message);
                //    }
                //  }
                //}
            }
            catch (Exception ex)
            {
                return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message));
            }
            return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "The event was closed successfuly! " + (iserror ? "(Note: watch the log file for details)" : String.Empty)));
        }