//GetEventCategoryById public EventCategory GetEventCategoryById(long id) { DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.EVENTS, "GETEVENTCATEGORYBYID", new object[] { id }, CachingExpirationTime.Days_01); EventCategory result = CacheRepository.Get(dco) as EventCategory; if (result != null) { return(result); } result = dataContext.spSelect_EventCategory(id).FirstOrDefault(); if (result != null) { dco.Data = result; CacheRepository.Add(dco); } return(result); }
//GetEventCategoryByMainCategory public EventCategory GetEventCategoryByMainCategory(long maincategory_id, long event_id) { DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.CATEGORIES, "GETEVENTCATEGORYBYMAINCATEGORY", new object[] { maincategory_id, event_id }, CachingExpirationTime.Hours_01); EventCategory ec = CacheRepository.Get(dco) as EventCategory; if (ec != null) { return(ec); } ec = dataContext.spEventCategory_ByMainCategory(event_id, maincategory_id).FirstOrDefault(); if (ec != null) { dco.Data = ec; CacheRepository.Add(dco); } return(ec); }
//AddCategoryChildToEventCategory private void AddCategoryChildToEventCategory(Event evnt, CategoriesMap cm) { EventCategory evnt_cat = dataContext.EventCategories.SingleOrDefault(EC => EC.Event_ID == evnt.ID && EC.MainCategory_ID == cm.MainCategory_ID && EC.Category_ID == cm.Category_ID); if (evnt_cat == null) { evnt_cat = new EventCategory(); dataContext.EventCategories.InsertOnSubmit(evnt_cat); } evnt_cat.Category_ID = cm.Category_ID; evnt_cat.MainCategory_ID = cm.MainCategory_ID; evnt_cat.IsActive = true; evnt_cat.LastUpdate = DateTime.Now; evnt_cat.Owner_ID = AppHelper.CurrentUser.ID; evnt_cat.Event_ID = evnt.ID; evnt_cat.Descr = cm.FullCategory; //evnt_cat.FullCategory; evnt_cat.Priority = cm.Priority; evnt.EventCategories.Add(evnt_cat); }
//GetFullEventCategoryLink public string GetFullEventCategoryLink(long eventcategory_id) { DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.EVENTS, "FULLCATEGORYLINK_EC", new object[] { eventcategory_id }, CachingExpirationTime.Days_01); string result = CacheRepository.Get(dco) as string; if (!String.IsNullOrEmpty(result)) { return(result); } EventCategory ec = dataContext.spSelect_EventCategory(eventcategory_id).FirstOrDefault(); if (ec == null) { return("---"); } result = ec.FullCategoryLink; if (!string.IsNullOrEmpty(result)) { dco.Data = result; CacheRepository.Add(dco); } return(result); }
//MergingCategoriesMap public JsonExecuteResult MergingCategoriesMap(long cm_from, long cm_to) { if (cm_from == cm_to) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please select different source and destination categories."); try { using (TransactionScope ts = new TransactionScope()) { CategoriesMap From = dataContext.CategoriesMaps.SingleOrDefault(CM => CM.ID == cm_from); CategoriesMap To = dataContext.CategoriesMaps.SingleOrDefault(CM => CM.ID == cm_to); if (From == null || To == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, String.Format("The {0} category doesn't exists", (From == null) ? "source" : "destination")); List<CategoriesMap> catmaps = new List<CategoriesMap>(); List<Event> events = (from A in dataContext.Auctions where A.EventCategory.CategoriesMap.ID == cm_from select A.Event).Distinct<Event>().ToList(); if (events.Count() == 0) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The are no auctions in the source category for moving to a destination category"); EventCategory ec; List<Auction> auctions; foreach (Event evnt in events) { ec = evnt.EventCategories.SingleOrDefault(EC => EC.MainCategory_ID == To.MainCategory_ID && EC.Category_ID == To.Category_ID); if (ec == null) { ec = new EventCategory(); ec.Category_ID = To.Category_ID; ec.MainCategory_ID = To.MainCategory_ID; ec.IsActive = true; ec.LastUpdate = DateTime.Now; ec.Owner_ID = AppHelper.CurrentUser.ID; dataContext.EventCategories.InsertOnSubmit(ec); evnt.EventCategories.Add(ec); } auctions = (from A in dataContext.Auctions where A.EventCategory.Category_ID == From.Category_ID && A.EventCategory.MainCategory_ID == From.MainCategory_ID && A.Event_ID == evnt.ID select A).ToList(); auctions.ForEach(A => A.EventCategory = ec); } GeneralRepository.SubmitChanges(dataContext); ts.Complete(); } } 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; }