Example #1
0
 //GetEventUnpaidInvoicesForUser
 public List <InvoiceDetail> GetEventUnpaidInvoicesForUser(long user_id)
 {
     return((from p in dataContext.spInvoice_Detail_UserUnpaid(user_id)
             select new InvoiceDetail
     {
         Amount = p.Amount,
         AuctionType = p.AuctionType_ID,
         BuyerPremium = p.BuyerPremium.GetValueOrDefault(0),
         DateCreated = p.DateCreated,
         Discount = p.Discount.GetValueOrDefault(0),
         Insurance = p.Insurance.GetValueOrDefault(0),
         Invoice_ID = p.Invoice_ID,
         LinkParams = new LinkParams {
             ID = p.Auction_ID, Lot = p.Lot, Title = p.Title, Event_ID = p.Event_ID, EventTitle = p.EventTitle, EventCategory_ID = p.EventCategory_ID, CategoryTitle = p.Category
         },
         Quantity = p.Quantity,
         Shipping = p.Shipping.GetValueOrDefault(0),
         Tax = p.Tax.GetValueOrDefault(0),
         Total = p.TotalDue.GetValueOrDefault(0),
         IsConsignorShip = p.IsConsignorShip,
         UserInvoice_ID = p.UserInvoices_ID
     }).ToList());
 }
Example #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)));
        }