//UploadImage public JsonExecuteResult UploadImage(Auction auc, string file) { try { string path = DiffMethods.CheckOrCreateDirectory(auc.ID); System.Drawing.Image img, imgNew, imgThumb, imgLarge; img = System.Drawing.Image.FromFile(file); string prefix = (auc == null) ? (Directory.GetFiles(path, "thmb_*.*").Count() + 1).ToString() + "_" + DateTime.Now.Ticks.ToString() : auc.ID.ToString() + "-" + ((auc == null || auc.Images == null) ? 0 : auc.Images.Count + 1).ToString() + "_" + DateTime.Now.Ticks.ToString(); prefix += Path.GetExtension(file); imgNew = DiffMethods.ChangeImageSize(img, (img.Width > img.Height) ? (int?)Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Medium) : null, (img.Width > img.Height) ? null : (int?)Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Medium), false); imgThumb = DiffMethods.ChangeImageSize(img, Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Small), null, false); imgLarge = (img.Width <= Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Large) || img.Height <= Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Large)) ? img : DiffMethods.ChangeImageSize(img, (img.Width > img.Height) ? (int?)Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Large) : null, (img.Width > img.Height) ? null : (int?)Consts.GetAuctionImageSize(Consts.AuctionImagesSize.Large), false); imgNew.Save(Path.Combine(path, prefix), System.Drawing.Imaging.ImageFormat.Jpeg); imgThumb.Save(Path.Combine(path, "thmb_" + prefix), System.Drawing.Imaging.ImageFormat.Jpeg); imgLarge.Save(Path.Combine(path, "xl_" + prefix), System.Drawing.Imaging.ImageFormat.Jpeg); img.Dispose(); imgNew.Dispose(); imgThumb.Dispose(); imgLarge.Dispose(); Image imgnew = AddAuctionImg(auc.ID, prefix, Path.GetFileName(file)); if (imgnew != null) auc.Images.Add(imgnew); } catch (System.Runtime.InteropServices.ExternalException ex) { throw new System.Runtime.InteropServices.ExternalException(ex.Message); } catch (Exception ex) { return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message); } return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS); }
//UpdateDOW public bool UpdateDOW(DOWForm 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.Where(E => E.ID == 0).FirstOrDefault(); bool IsNew = false; try { Auction auction = GetAuction(info.ID); if (IsNew = (auction == null)) { auction = new Auction(); dataContext.Auctions.InsertOnSubmit(auction); auction.NotifiedOn = DateTime.Now; } auction.AuctionType_ID = (byte)Consts.AuctionType.DealOfTheWeek; auction.Event_ID = 0; auction.Owner_ID = info.Owner_ID.HasValue ? info.Owner_ID.Value : AppHelper.CurrentUser.ID; auction.CommissionRate_ID = info.CommissionRate_ID; auction.OldAuction_ID = (!IsCopy) ? info.OldAuction_ID : old.ID; auction.Price = info.Price.Value; auction.Reserve = info.Price; auction.Status = info.Status_ID; auction.Title = info.Title; auction.Shipping = info.Shipping; auction.Description = info.Description; auction.Addendum = info.Addendum; info.MainCategory_ID = IsCopy ? old.EventCategory.MainCategory_ID : 0; EventCategory ec = dataContext.EventCategories.Where(EC => EC.Event_ID == 0 && EC.MainCategory_ID == info.MainCategory_ID && EC.Category_ID == info.Category_ID).FirstOrDefault(); if (ec == null) { ec = new EventCategory(); ec.Event_ID = 0; ec.MainCategory_ID = info.MainCategory_ID; ec.IsActive = false; ec.Owner_ID = AppHelper.CurrentUser.ID; ec.Category_ID = info.Category_ID; ec.Priority = 1; ec.LastUpdate = DateTime.Now; dataContext.EventCategories.InsertOnSubmit(ec); } auction.EventCategory = ec; auction.Cost = 0; auction.StartDate = evnt.DateStart; auction.EndDate = evnt.DateEnd; auction.Quantity = 1; auction.Estimate = String.Empty; auction.ListedStep = 0; auction.Priority = 1; auction.LOA = false; auction.PulledOut = false; auction.IsUnsold = false; auction.IsCatalog = false; auction.IsPrinted = false; auction.CopyNotes = String.Empty; auction.PhotoNotes = String.Empty; auction.LastUpdate = DateTime.Now; auction.IsBold = false; auction.IsFeatured = false; auction.IsPhotographed = false; auction.IsInLayout = false; auction.IsLimitDisabled = false; if (IsCopy && IsNew) { List<Image> imgs = dataContext.Images.Where(I => I.Auction_ID == auction.ID).ToList(); if (imgs != null && imgs.Count() > 0) dataContext.Images.DeleteAllOnSubmit(imgs); } GeneralRepository.SubmitChanges(dataContext); if (IsCopy && old.Images.Count() > 0 && IsNew) { 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; i1.isChecked = i2.isChecked; dataContext.Images.InsertOnSubmit(i1); auction.Images.Add(i1); } GeneralRepository.SubmitChanges(dataContext); } if (IsCopy && !DiffMethods.CopyImages(old.ID, auction.ID)) Logger.LogException(new Exception("Images don't exist for auction " + old.ID.ToString())); if (IsNew) { if (IsCopy && old.Event_ID > 0) AddConsignment(auction.Owner_ID, old.Event_ID); else AddConsignment(auction.Owner_ID, auction.Event_ID); MoveImagesToAction(auction.ID); } } catch (ChangeConflictException cce) { Logger.LogException(cce); throw cce; } catch (Exception ex) { Logger.LogException(ex); throw ex; } return true; }
//AddNewItemForConsignorStatement public bool UpdateItemForConsignorStatement(NewAuctionForConsignorForm info) { Auction old = (info.OldInventory.HasValue) ? GetAuction(info.OldInventory.Value) : null; bool IsCopy = (info.OldInventory.HasValue && old != null); Event evnt = dataContext.Events.SingleOrDefault(E => E.ID == info.Event_ID); bool IsNew; try { Auction auction = GetAuction(info.Auction_ID); using (TransactionScope ts = new TransactionScope()) { IsNew = (auction == null); if (IsNew) { auction = new Auction(); dataContext.Auctions.InsertOnSubmit(auction); auction.EnteredBy = AppHelper.CurrentUser.ID; auction.NotifiedOn = DateTime.Now; auction.Event_ID = info.Event_ID; auction.StartDate = evnt.DateStart; auction.EndDate = evnt.DateEnd.AddDays(2); auction.IsInLayout = false; auction.IsPhotographed = false; } auction.AuctionType_ID = (byte)Consts.AuctionType.Normal; //(byte)((info.Quantity == 1) ? Consts.AuctionType.Normal : Consts.AuctionType.Dutch); auction.CommissionRate_ID = info.CommissionRate_ID; auction.CopyNotes = info.CopyNotes; auction.IsBold = (!IsCopy) ? (false) : old.IsBold; auction.IsFeatured = (!IsCopy) ? (false) : old.IsFeatured; auction.LastUpdate = DateTime.Now; auction.LOA = info.LOA; auction.OldAuction_ID = (!IsCopy) ? (info.OldInventory) : old.ID; auction.Owner_ID = info.User_ID; auction.PhotoNotes = info.PhotoNotes; auction.Price = info.Price.GetValueOrDefault(0); auction.Reserve = info.Price.GetValueOrDefault(0); auction.Priority = info.Priority; auction.Quantity = info.Quantity; auction.Status = (IsNew) ? ((byte)((evnt.DateStart > DateTime.Now) ? Consts.AuctionStatus.Pending : Consts.AuctionStatus.Locked)) : auction.Status; auction.Title = info.Title; auction.PulledOut = false; auction.Description = info.Description; auction.IsPrinted = false; auction.ListedStep = info.ListingStep; auction.IsLimitDisabled = info.IsLimitDisabled; EventCategory ec = dataContext.EventCategories.SingleOrDefault(EC => EC.MainCategory_ID == info.MainCategory_ID && EC.Category_ID == info.Category_ID.Value && EC.Event_ID == info.Event_ID); if (ec == null) throw new Exception("Event category doesn't exist."); auction.Category_ID = ec.ID; if (IsCopy) { auction.Cost = old.Cost; auction.Estimate = old.Estimate; auction.Shipping = old.Shipping; } GeneralRepository.SubmitChanges(dataContext); if (IsCopy && old.Images.Count() > 0) { 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; i1.isChecked = i2.isChecked; dataContext.Images.InsertOnSubmit(i1); auction.Images.Add(i1); } GeneralRepository.SubmitChanges(dataContext); } if (IsCopy && !DiffMethods.CopyImages(old.ID, auction.ID)) Logger.LogException(new Exception("Images don't exist for auction " + old.ID.ToString())); ts.Complete(); } AuctionExtended ae = dataContext.AuctionExtendeds.Where(a => a.Auction_ID == auction.ID).FirstOrDefault(); 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); } 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; }
//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; }