/// <summary> /// returns all the children for the specified news type. /// </summary> /// <param name="parent"></param> /// <returns></returns> public IQueryable <NewsType> GetTypes(string parent) { int parentId = -1; NewsType _parent = GetType(parent); if (_parent != null) { parentId = _parent.TypeId; } return(from newsType in GetTypes() where newsType.ParentId == parentId orderby newsType.Ranking descending select newsType); }
partial void DeleteNewsType(NewsType instance);
partial void UpdateNewsType(NewsType instance);
partial void InsertNewsType(NewsType instance);
public int AddNewsType(string Name, Status Status, HttpPostedFile Image, string Description, int?ParentId, short?ThumbWidth, short?ThumbHeight, short?MediumWidth, short?MediumHeight, short?LargeWidth, short?LargeHeight, int?TemplateId, int?Permission) { if (GetType(Name) != null) { return(-1); } NewsType type = new NewsType { Name = Name, UniqueName = StringUtils.ToURL(Name), Status = (byte)Status, Description = Description, ParentId = ParentId, ThumbWidth = ThumbWidth, ThumbHeight = ThumbHeight, MediumWidth = MediumWidth, MediumHeight = MediumHeight, LargeWidth = LargeWidth, LargeHeight = LargeHeight, DateCreated = DateTime.Now, LastModified = DateTime.Now, TemplateId = TemplateId, Ranking = 0, UserRating = 0, Views = 0, Permission = Permission }; NewsTypesData.NewsTypes.InsertOnSubmit(type); NewsTypesData.SubmitChanges(); if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, type.TypeId, Path.GetExtension(Image.FileName)); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.NewsTypesFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, ImageName); Image.SaveAs(path); if (ThumbWidth > 0 && ThumbHeight > 0) { ImageUtils.CropImage(path, path, (int)ThumbWidth, (int)ThumbHeight, ImageUtils.AnchorPosition.Default); } type.Image = ImageName; NewsTypesData.SubmitChanges(); } return(type.TypeId); }
/// <summary> /// change the ranking for the current record and updates the other ones accordingly. /// </summary> /// <param name="id"></param> /// <param name="d"></param> /// <param name="ss"></param> /// <param name="pid"></param> /// <returns></returns> public void UpdateRanking(int id, int d, int ss, int?pid) { if ((d != 1) && (d != -1)) { throw new Exception("Direction value incorrect"); } IQueryable <New> allNews = null; IQueryable <NewsType> allTypes = null; if (pid.HasValue && pid.Value > 0) { NewsManager nMgr = new NewsManager(); New selectedRecord = nMgr.NewsData.News.SingleOrDefault(x => x.NewsId == id); if (selectedRecord == null) { throw new Exception("Record not found"); } allNews = from newsTypeView in nMgr.NewsData.News where newsTypeView.NewsType == pid select newsTypeView; // increasing priority if (d == -1) { //select all where priority > currentPriority and limiting results to maximum the stepsize var recordsToUpdate = (from s in allNews where s.Ranking > selectedRecord.Ranking orderby s.Ranking select s).Take(ss); if (recordsToUpdate.Count() > 0) { int maxPriority = Convert.ToInt32(recordsToUpdate.Max(x => x.Ranking)); foreach (var s in recordsToUpdate) { s.Ranking--; } selectedRecord.Ranking = maxPriority; nMgr.Save(); } } // lowering priority if (d == 1) { if (selectedRecord == null) { throw new Exception("Record not found"); } //select all where priority < currentPriority and limiting results to maximum the stepsize var recordsToUpdate = (from s in allNews where s.Ranking < selectedRecord.Ranking orderby s.Ranking descending select s).Take(ss); if (recordsToUpdate.Count() > 0) { int minimumPriority = Convert.ToInt32(recordsToUpdate.Min(x => x.Ranking)); foreach (var s in recordsToUpdate) { s.Ranking++; } selectedRecord.Ranking = minimumPriority; nMgr.Save(); } } } else { NewsType selectedRecord = GetType(id); allTypes = from newsType in GetTypes() where newsType.ParentId == 12 select newsType; if (selectedRecord == null) { throw new Exception("Record not found"); } // increasing priority if (d == -1) { //select all where priority > currentPriority and limiting results to maximum the stepsize var recordsToUpdate = (from s in allTypes where s.Ranking > selectedRecord.Ranking orderby s.Ranking select s).Take(ss); if (recordsToUpdate.Count() > 0) { int maxPriority = Convert.ToInt32(recordsToUpdate.Max(x => x.Ranking)); foreach (var s in recordsToUpdate) { s.Ranking--; } selectedRecord.Ranking = maxPriority; this.Save(); } } // lowering priority if (d == 1) { //select all where priority < currentPriority and limiting results to maximum the stepsize var recordsToUpdate = (from s in allTypes where s.Ranking < selectedRecord.Ranking orderby s.Ranking descending select s).Take(ss); if (recordsToUpdate.Count() > 0) { int minimumPriority = Convert.ToInt32(recordsToUpdate.Min(x => x.Ranking)); foreach (var s in recordsToUpdate) { s.Ranking++; } selectedRecord.Ranking = minimumPriority; this.Save(); } } } }