Example #1
0
 public MarketPlace()
 {
     _auctions = new AuctionCollection();
     _settlements = new List<Settlement>();
 }
Example #2
0
        public override AuctionCollection GetAuctions(bool openOnly,bool getLastStage)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "Chinaz_LoadAuctions";
                query.CommandType = CommandType.StoredProcedure;
                query.CreateParameter<bool>("@GetLastStage",getLastStage, SqlDbType.Bit);

                AuctionCollection auctions = new AuctionCollection();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    auctions = new AuctionCollection(reader);

                    if (getLastStage && reader.NextResult())
                    {
                        while (reader.Next)
                        {
                            AuctionStage stage = new AuctionStage(reader);

                            foreach (Auction auc in auctions)
                            {
                                if (auc.AuctionID == stage.AuctionID)
                                {
                                    auc.LastStage = stage;
                                }
                            }
                        }

                        if (reader.NextResult())
                        {
                            AuctionBidInfo bid;
                            while (reader.Next)
                            {
                                bid = new AuctionBidInfo(reader);

                                foreach (Auction auc in auctions)
                                {
                                    if (auc.LastStage != null
                                        && auc.LastStage.StageID == bid.StageID
                                        && auc.AuctionID == bid.AuctionID)
                                    {
                                        if (auc.LastStage.LastBid == null)
                                        {
                                            auc.LastStage.LastBid = bid;
                                        }
                                        else if (auc.LastStage.LastBid.Price < bid.Price)
                                        {
                                            auc.LastStage.LastBid = bid;
                                        }
                                        if (auc.LastStage.EndTime > DateTimeUtil.Now)
                                            auc.LastStage.BidList.Add(bid);
                                    }
                                }
                            }
                        }
                    }

                    return auctions;
                }
            }
        }
Example #3
0
        public override AuctionCollection GetAuctions(bool openOnly, bool getLastStage)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "Chinaz_LoadAuctions";
                query.CommandType = CommandType.StoredProcedure;
                query.CreateParameter <bool>("@GetLastStage", getLastStage, SqlDbType.Bit);

                AuctionCollection auctions = new AuctionCollection();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    auctions = new AuctionCollection(reader);

                    if (getLastStage && reader.NextResult())
                    {
                        while (reader.Next)
                        {
                            AuctionStage stage = new AuctionStage(reader);

                            foreach (Auction auc in auctions)
                            {
                                if (auc.AuctionID == stage.AuctionID)
                                {
                                    auc.LastStage = stage;
                                }
                            }
                        }

                        if (reader.NextResult())
                        {
                            AuctionBidInfo bid;
                            while (reader.Next)
                            {
                                bid = new AuctionBidInfo(reader);

                                foreach (Auction auc in auctions)
                                {
                                    if (auc.LastStage != null &&
                                        auc.LastStage.StageID == bid.StageID &&
                                        auc.AuctionID == bid.AuctionID)
                                    {
                                        if (auc.LastStage.LastBid == null)
                                        {
                                            auc.LastStage.LastBid = bid;
                                        }
                                        else if (auc.LastStage.LastBid.Price < bid.Price)
                                        {
                                            auc.LastStage.LastBid = bid;
                                        }
                                        if (auc.LastStage.EndTime > DateTimeUtil.Now)
                                        {
                                            auc.LastStage.BidList.Add(bid);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(auctions);
                }
            }
        }
        //UpdateAuction
        public bool UpdateAuction(AuctionForm info)
        {
            Auction old = (info.OldAuction_ID.HasValue) ? GetAuction(info.OldAuction_ID.Value) : null;
            bool IsCopy = (info.OldAuction_ID.HasValue && old != null);
            Event evnt = dataContext.Events.FirstOrDefault(t => t.ID == info.Event_ID);
            bool IsNew = false;
            bool isoldpulledout = false;
            try
            {
                Auction auction = GetAuction(info.ID);
                using (TransactionScope ts = new TransactionScope())
                {
                    if (IsNew = (auction == null))
                    {
                        auction = new Auction();
                        dataContext.Auctions.InsertOnSubmit(auction);
                        auction.EnteredBy = AppHelper.CurrentUser.ID;
                        auction.NotifiedOn = DateTime.Now;
                    }
                    if (IsCopy && auction.ID == old.ID)
                    {
                        IsCopy = false;
                        old = null;
                        info.OldAuction_ID = null;
                    }
                    auction.AuctionType_ID = (byte)Consts.AuctionType.Normal; //(byte)((info.Quantity == 1) ? Consts.AuctionType.Normal : Consts.AuctionType.Dutch);
                    if (IsNew)
                    {
                        auction.Event_ID = info.Event_ID;
                        auction.StartDate = evnt.DateStart;
                        auction.EndDate = evnt.DateEnd.AddDays(2);
                    }
                    else
                    {
                        isoldpulledout = (auction.PulledOut.HasValue && auction.PulledOut.Value) || auction.Status == (byte)Consts.AuctionStatus.PulledOut;
                    }
                    auction.Owner_ID = info.Owner_ID.Value;
                    auction.CommissionRate_ID = info.CommissionRate_ID;
                    auction.Status = info.Status_ID; //(byte)((evnt.DateStart > DateTime.Now) ? Consts.AuctionStatus.Pending : Consts.AuctionStatus.Locked);
                    auction.Title = info.Title;
                    auction.Lot = info.Lot;
                    EventCategory ec = dataContext.EventCategories.SingleOrDefault(t => t.MainCategory_ID == info.MainCategory_ID && t.Category_ID == info.Category_ID.Value && t.Event_ID == info.Event_ID);
                    if (ec == null) throw new Exception("Event category doesn't exist.");
                    auction.Category_ID = ec.ID;
                    auction.Quantity = info.Quantity.HasValue ? info.Quantity.Value : 1;
                    auction.Price = info.Reserve.Value;
                    auction.Reserve = info.Reserve.Value;
                    auction.Estimate = info.Estimate;
                    auction.Shipping = info.Shipping;
                    auction.ListedStep = info.ListingStep;
                    auction.Priority = info.Priority.Value;
                    auction.LOA = info.LOA;
                    auction.Addendum = info.Addendum;
                    auction.OldAuction_ID = (!IsCopy) ? (info.OldAuction_ID) : old.ID;
                    auction.PulledOut = info.PulledOut;
                    auction.IsUnsold = info.IsUnsold;
                    auction.IsCatalog = info.IsCatalog;
                    auction.IsPrinted = info.IsPrinted;
                    auction.Description = info.Description;
                    auction.CopyNotes = info.CopyNotes;
                    auction.PhotoNotes = info.PhotoNotes;
                    auction.LastUpdate = DateTime.Now;
                    auction.IsBold = (IsCopy) && old.IsBold;
                    auction.IsFeatured = (IsCopy) && old.IsFeatured;
                    auction.IsPhotographed = info.IsPhotographed;
                    auction.IsInLayout = info.IsInLayout;
                    auction.IsLimitDisabled = info.IsLimitDisabled;
                    auction.IsCatalog = info.IsCatalog;
                    if (auction.PulledOut.Value || auction.Status == (byte)Consts.AuctionStatus.PulledOut)
                    {
                        auction.PulledOut = true;
                        auction.Status = (byte)Consts.AuctionStatus.PulledOut;
                        if (!IsNew && !isoldpulledout)
                        {
                            if (auction.Event.IsCurrent)
                            {
                                List<BidWatch> bw = dataContext.BidWatches.Where(t => t.Auction_ID == auction.ID).ToList();
                                bw.ForEach(t => Mail.SendPulledOutLetter(t.User.AddressCard_Billing.FirstName, t.User.AddressCard_Billing.LastName, t.User.Email, auction.ID, auction.Title));
                            }
                        }
                    }
                    if (IsCopy)
                    {
                        auction.Cost = old.Cost;
                    }
                    GeneralRepository.SubmitChanges(dataContext);

                    List<long> tags = (from t in dataContext.AuctionTags where t.AuctionID == auction.ID select t.TagID).ToList();
                    foreach (long tagID in info.Tags)
                    {
                        if (tags.Contains(tagID)) tags.Remove(tagID);
                        else
                        {
                            dataContext.AuctionTags.InsertOnSubmit(new AuctionTag { AuctionID = auction.ID, TagID = tagID });
                        }
                    }
                    foreach (long tagID in tags)
                    {
                        var r = dataContext.AuctionTags.FirstOrDefault(a => a.AuctionID == auction.ID && a.TagID == tagID);
                        if (r != null)
                            dataContext.AuctionTags.DeleteOnSubmit(r);
                    }

                    GeneralRepository.SubmitChanges(dataContext);
                   // List<Image> images = dataContext.Images.Where(a => a.Auction_ID == auction.ID).OrderByDescending(a => a.Default).ThenBy(a => a.Order).ToList();
                   //Alan 11/10/2015
                    if (info.ImagesTag != null)
                        foreach (string imgDesc in info.ImagesTag)
                        {
                            string[] imgArray = imgDesc.Split('|');

                            long imgId = Convert.ToInt64(imgArray[1]);
                            bool isChecked =Convert.ToBoolean( Convert.ToInt32(imgArray[0]));
                            Image r = dataContext.Images.FirstOrDefault(i => i.ID == imgId && i.Auction_ID == auction.ID);
                            if (r != null)
                            {

                                r.isChecked = isChecked;

                                GeneralRepository.SubmitChanges(dataContext);

                            }

                        }

                    if (IsCopy && !DiffMethods.CopyImages(old.ID, auction.ID))
                        Logger.LogException(new Exception("Images don't exist for auction " + old.ID));
                    if (IsNew)
                    {
                        AddConsignment(auction.Owner_ID, auction.Event_ID);
                        MoveImagesToAction(auction.ID);
                    }

                    if (IsNew && IsCopy && old.Images.Any())
                    {
                        //Image i1;
                        //foreach (Image i2 in old.Images)
                        //{
                        //  i1 = (!IsNew) ? auction.Images.FirstOrDefault(I => I.PicturePath == i2.PicturePath) : null;
                        //  if (i1 != null) continue;
                        //  i1 = i1 ?? new Image();
                        //  i1.Auction_ID = auction.ID;
                        //  i1.Default = i2.Default;
                        //  i1.PicturePath = i2.PicturePath;
                        //  i1.ThumbNailPath = i2.ThumbNailPath;
                        //  i1.LargePath = i2.LargePath;
                        //  i1.Order = i2.Order;
                        //  i1.UploadedFileName = i2.UploadedFileName;
                        //  dataContext.Images.InsertOnSubmit(i1);
                        //  auction.Images.Add(i1);
                        //}
                        //GeneralRepository.SubmitChanges(dataContext);

                        List<Image> imgs = dataContext.Images.Where(a => a.Auction_ID == auction.ID).OrderByDescending(a => a.Default).ThenBy(a => a.Order).ToList();
                        int imagecount = imgs.Count();
                        bool isimages = imagecount > 0; //auction.Images.Count() > 0;
                        int maxOrder = imagecount > 0 ? imgs.Max(m => m.Order) : 0;
                        Image i1;
                        foreach (Image i2 in old.Images)
                        {
                            i1 = new Image
                              {
                                  Auction_ID = auction.ID,
                                  Default = !isimages && i2.Default,
                                  PicturePath = i2.PicturePath,
                                  ThumbNailPath = i2.ThumbNailPath,
                                  LargePath = i2.LargePath,
                                  Order = ++maxOrder,
                                  UploadedFileName = i2.UploadedFileName
                              };
                            dataContext.Images.InsertOnSubmit(i1);
                            imgs.Add(i1);
                        }
                        GeneralRepository.SubmitChanges(dataContext);
                        SetImageAsDefault(auction.ID, imgs[0].ID);
                        if (DiffMethods.CopyImages(old.ID, auction.ID))
                            Logger.LogException(new Exception("Images don't exist for auction " + old.ID));
                    }
                    ts.Complete();
                }

                AuctionExtended ae = dataContext.AuctionExtendeds.FirstOrDefault(a => a.Auction_ID == auction.ID);
                if (info.PurchasedPrice.HasValue || info.SoldPrice.HasValue || info.PurchasedWay.GetValueOrDefault(-1) > 0 || info.SoldWay.GetValueOrDefault(-1) > 0)
                {
                    if (ae == null)
                    {
                        ae = new AuctionExtended();
                        dataContext.AuctionExtendeds.InsertOnSubmit(ae);
                        ae.Auction_ID = auction.ID;
                    }
                    ae.PurchasedWay = info.PurchasedWay.HasValue && info.PurchasedWay.GetValueOrDefault(-1) > 0 ? info.PurchasedWay : null;
                    ae.SoldWay = info.SoldWay.HasValue && info.SoldWay.GetValueOrDefault(-1) > 0 ? info.SoldWay : null;
                    ae.PurchasedPrice = info.PurchasedPrice.HasValue && info.PurchasedPrice.GetValueOrDefault(-1) > 0 ? info.PurchasedPrice : null;
                    ae.SoldPrice = info.SoldPrice.HasValue && info.SoldPrice.GetValueOrDefault(-1) > 0 ? info.SoldPrice : null;
                    GeneralRepository.SubmitChanges(dataContext);
                }
                else if (ae != null)
                {
                    dataContext.AuctionExtendeds.DeleteOnSubmit(ae);
                    GeneralRepository.SubmitChanges(dataContext);
                }

                AuctionCollection auctionCollection = dataContext.AuctionCollections.FirstOrDefault(t => t.AuctionID == auction.ID);
                if (info.CollectionID.HasValue)
                {
                    if (auctionCollection == null)
                    {
                        auctionCollection = new AuctionCollection { AuctionID = auction.ID };
                        dataContext.AuctionCollections.InsertOnSubmit(auctionCollection);
                    }
                    auctionCollection.CollectionID = info.CollectionID.Value;
                    GeneralRepository.SubmitChanges(dataContext);
                }
                else if (auctionCollection != null)
                {
                    dataContext.AuctionCollections.DeleteOnSubmit(auctionCollection);
                    GeneralRepository.SubmitChanges(dataContext);
                }

                if (evnt.IsViewable)
                {
                    try
                    {
                        System.Net.WebClient client = new System.Net.WebClient();
                        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                        client.OpenRead(Consts.CacheClearFrontendIP + Consts.FrontEndClearADPMethod + "/" + auction.ID);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException("[" + Consts.CacheClearFrontendIP + Consts.FrontEndClearADPMethod + "/" + auction.ID + "]", ex);
                    }
                }
            }
            catch (ChangeConflictException cce)
            {
                Logger.LogException(cce);
                throw cce;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw ex;
            }
            return true;
        }