//GetCategoryMapDescription public JsonExecuteResult GetCategoryMapDescription(long catmap_id) { List <string> str = new List <string>(); CategoriesMap cm = dataContext.CategoriesMaps.SingleOrDefault(CM => CM.ID == catmap_id); List <CategoriesMap> catmaps = new List <CategoriesMap>(); try { var res = from A in dataContext.Auctions where A.EventCategory.CategoriesMap.ID == catmap_id orderby A.Status group A.Status by A.Status; foreach (var r in res) { if (r.Count() == 0) { continue; } str.Add(String.Format("{0} {1} auction{2}", r.Count(), ((Consts.AuctionStatus)r.Key).ToString().ToLower(), (r.Count() > 1) ? "s" : String.Empty)); } } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return((str.Count() > 0) ? new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "", str.ToArray()) : new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "There are no auctions in this category.", null)); }
//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)); }
private void GetParentCategoryLink(StringBuilder sb, CategoriesMap cm, bool demo) { if (cm == null || cm.CategoriesMap_Parent == null || cm.CategoriesMap_Parent.ID == cm.ID) { return; } cm = cm.CategoriesMap_Parent; sb.Insert(0, "<span> > </span>"); sb.Insert(0, String.Format("<a href='{0}/?e={2}'>{1}</a>", AppHelper.GetSiteUrl("/" + (demo?"Preview":"Auction") + "/Category/" + cm.ID + "/" + UrlParser.TitleToUrl(cm.Category.Title)), cm.Category.Title, Event_ID)); GetParentCategoryLink(sb, cm, demo); }
private void GetParentCategory(StringBuilder sb, CategoriesMap cm) { if (cm == null || cm.Category == null) { return; } sb.Insert(0, cm.Category.Title); if (cm.CategoriesMap_Parent == null || cm.CategoriesMap_Parent.ID == cm.ID) { return; } sb.Insert(0, " > "); GetParentCategory(sb, cm.CategoriesMap_Parent); }
//GetCategoryMapById public CategoriesMap GetCategoryMapById(long id) { DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.CATEGORIES, "GETCATEGORYMAPBYID", new object[] { id }, CachingExpirationTime.Days_01); CategoriesMap result = CacheRepository.Get(dco) as CategoriesMap; if (result != null) { return(result); } result = dataContext.spSelect_CategoriesMap(id).FirstOrDefault(); if (result != null) { dco.Data = result; CacheRepository.Add(dco); } return(result); }
//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); }
//DeleteCategoryMap public JsonExecuteResult DeleteCategoryMap(long catmap_id) { try { CategoriesMap cm = (catmap_id == -1) ? null : GetCategoryMap(catmap_id); if (cm == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "This category map doesn't exists")); } long count = dataContext.Auctions.Where(EC => EC.EventCategory.MainCategory_ID == cm.MainCategory_ID && EC.EventCategory.Category_ID == cm.Category_ID).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this record because there are auctions which are using this category.")); } dataContext.CategoriesMaps.DeleteOnSubmit(cm); GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
//AddSubCategoriesMap public void AddSubCategoriesMap(List <CategoriesMap> catmap, CategoriesMap cm) { catmap.Add(cm); // foreach (CategoriesMap _cm in cm.CategoriesMap_Children) // AddSubCategoriesMap(catmap, _cm); }
//UpdateCategoryMap public JsonExecuteResult UpdateCategoryMap(long catmap_id, int maincat_id, long cat_id, string descr, string intro, int priority, bool isactive, bool isdefault) { try { MainCategory mc = GetMainCategory(maincat_id); Category c = GetCategory(cat_id); if (mc == null || c == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The main category or category doesn't exist.")); } bool newCategory = false; CategoriesMap cat = (catmap_id == -1) ? null : GetCategoryMap(catmap_id); if (cat == null) { if ((cat = dataContext.CategoriesMaps.Where(CM => CM.MainCategory_ID == mc.ID && CM.Category_ID == c.ID).FirstOrDefault()) != null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't add this record, because the combination of this Main Category and Category already exists - CM# " + cat.ID.ToString())); } cat = new CategoriesMap(); dataContext.CategoriesMaps.InsertOnSubmit(cat); newCategory = true; } cat.MainCategory_ID = maincat_id; cat.Category_ID = cat_id; cat.Descr = String.IsNullOrEmpty(descr) ? mc.Title + " > " + c.Title : descr; cat.Intro = intro; cat.IsActive = isactive; cat.Priority = priority; cat.Owner_ID = AppHelper.CurrentUser.ID; cat.LastUpdate = DateTime.Now; cat.IsDefault = isdefault; if (!newCategory && !cat.IsActive) { List <CategoriesMap> Cat = dataContext.CategoriesMaps.Where(C => C.Category_ID == cat.ID).ToList(); foreach (CategoriesMap cm in Cat) { cm.IsActive = cat.IsActive; } if (dataContext.Auctions.Where(A => A.EventCategory.MainCategory_ID == cat.ID).Count() > 0) { List <string> str = new List <string>(); var res = from A in dataContext.Auctions where A.EventCategory.MainCategory_ID == cat.ID && A.Status != (byte)Consts.AuctionStatus.Locked orderby A.Status group A.Status by A.Status; foreach (var r in res) { if (r.Count() > 0) { str.Add(String.Format("{0} {1} auction{2}", r.Count(), ((Consts.AuctionStatus)r.Key).ToString().ToLower(), (r.Count() > 1) ? "s" : String.Empty)); } } if (str.Count() > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't set this category as unactive, because there are auctions in the database which are using this category.", str.ToArray())); } } } if (newCategory) { cat.ID = dataContext.MainCategories.Max(E => E.ID) + 1; } GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
//UpdateCategoryMap public JsonExecuteResult UpdateCategoryMap(long catmap_id, int maincat_id, long cat_id, string descr, string intro, int priority, bool isactive, bool isdefault) { try { MainCategory mc = GetMainCategory(maincat_id); Category c = GetCategory(cat_id); if (mc == null || c == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The main category or category doesn't exist."); bool newCategory = false; CategoriesMap cat = (catmap_id == -1) ? null : GetCategoryMap(catmap_id); if (cat == null) { if ((cat = dataContext.CategoriesMaps.Where(CM=>CM.MainCategory_ID==mc.ID&&CM.Category_ID==c.ID).FirstOrDefault()) != null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't add this record, because the combination of this Main Category and Category already exists - CM# "+cat.ID.ToString()); cat = new CategoriesMap(); dataContext.CategoriesMaps.InsertOnSubmit(cat); newCategory = true; } cat.MainCategory_ID = maincat_id; cat.Category_ID = cat_id; cat.Descr = String.IsNullOrEmpty(descr) ? mc.Title +" > "+c.Title : descr; cat.Intro = intro; cat.IsActive = isactive; cat.Priority = priority; cat.Owner_ID = AppHelper.CurrentUser.ID; cat.LastUpdate = DateTime.Now; cat.IsDefault = isdefault; if (!newCategory && !cat.IsActive) { List<CategoriesMap> Cat = dataContext.CategoriesMaps.Where(C => C.Category_ID == cat.ID).ToList(); foreach (CategoriesMap cm in Cat) cm.IsActive = cat.IsActive; if (dataContext.Auctions.Where(A => A.EventCategory.MainCategory_ID == cat.ID).Count() > 0) { List<string> str = new List<string>(); var res = from A in dataContext.Auctions where A.EventCategory.MainCategory_ID == cat.ID && A.Status != (byte)Consts.AuctionStatus.Locked orderby A.Status group A.Status by A.Status; foreach (var r in res) { if (r.Count() > 0) str.Add(String.Format("{0} {1} auction{2}", r.Count(), ((Consts.AuctionStatus)r.Key).ToString().ToLower(), (r.Count() > 1) ? "s" : String.Empty)); } if (str.Count() > 0) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't set this category as unactive, because there are auctions in the database which are using this category.", str.ToArray()); } } if (newCategory) cat.ID = dataContext.MainCategories.Max(E => E.ID) + 1; GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message); } return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS); }
//AddSubCategoriesMap public void AddSubCategoriesMap(List<CategoriesMap> catmap, CategoriesMap cm) { catmap.Add(cm); // foreach (CategoriesMap _cm in cm.CategoriesMap_Children) // AddSubCategoriesMap(catmap, _cm); }
//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); }