void uiSaveButton_Click(object sender, EventArgs e) { if (!uiPlacesChooser.SelectedPlaceKs.Any()) { throw new Exception("You cannot visit nowhere. This should not have been an available option from the site"); } using (var transaction = new Transaction()) { Delete delete = new Delete(TablesEnum.UsrPlaceVisit, new Q(UsrPlaceVisit.Columns.UsrK, Usr.Current.K)); delete.Run(transaction); foreach (var item in this.uiPlacesChooser.SelectedPlaceKs) { UsrPlaceVisit utv = new UsrPlaceVisit(); utv.UsrK = Usr.Current.K; utv.PlaceK = item; utv.Update(transaction); } transaction.Commit(); Usr.Current.UpdatePlacesVisitCount(true); } this.uiSaveButton.Attributes["disabled"] = "true"; }
public static Tag AddTag(string tagText, Tagging.ITaggable objectToTag, Usr usrAddingTag) { try { Transaction t = new Transaction(); try { Tag tag = Tag.GetTag(tagText); if (tag.Blocked) { throw new InvalidTagException(); } TagPhoto tagPhoto = TagPhoto.GetTagPhoto(tag.K, objectToTag.K); TagPhotoHistory.TagPhotoHistoryAction action = TagPhotoHistory.TagPhotoHistoryAction.Created; if (tagPhoto == null) { tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = objectToTag.K, Disabled = false }; tagPhoto.Update(t); action = TagPhotoHistory.TagPhotoHistoryAction.Created; } if (tagPhoto.Disabled) { if (!usrAddingTag.IsJunior) { throw new Exception("You do not have rights to re-enable that tag"); } tagPhoto.Disabled = false; tagPhoto.Update(t); action = TagPhotoHistory.TagPhotoHistoryAction.Enabled; } TagPhotoHistory history = new TagPhotoHistory() { DateTime = DateTime.Now, Action = action, UsrK = usrAddingTag.K, TagPhotoK = tagPhoto.K }; history.Update(t); t.Commit(); return tag; } catch (Exception ex) { t.Rollback(); throw ex; } } catch (InvalidTagException) { return null; } }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; BannerSet bs = new BannerSet( new Query( new Or( new Q(Banner.Columns.MiscGuid, this.Guid), new Q(Banner.Columns.MiscK, this.K), new Q(Banner.Columns.NewMiscK, this.K), new Q(Banner.Columns.FailedMiscK, this.K) ) ) ); foreach (Banner b in bs) { if (b.MiscGuid.Equals(this.Guid)) b.MiscGuid = Guid.Empty; if (b.MiscK == this.K) b.MiscK = 0; if (b.NewMiscK == this.K) b.NewMiscK = 0; if (b.FailedMiscK == this.K) b.FailedMiscK = 0; b.Update(transaction); } this.Delete(transaction); Storage.RemoveFromStore(Storage.Stores.Pix, this.Guid, this.Extention); }
/// <summary> /// UPDATE Table SET Changes [FROM From] WHERE [Where] /// </summary> public int Run(Transaction transaction) { Dictionary<string, SqlParameter> paramHash = new Dictionary<string, SqlParameter>(); string rankContribution = ""; StringBuilder sb = new StringBuilder(); sb.Append("UPDATE ["); sb.Append(Tables.GetTableName(Table)); sb.Append("] SET "); bool first = true; foreach (Assign a in Changes) { if (a != null) { if (!first) sb.Append(", "); a.BuildString(sb, ref paramHash, ref rankContribution); first = false; } } if (From != null) { sb.Append(" FROM "); sb.Append(From.ToString(ref paramHash, ref rankContribution, false)); } if (Where == null) throw new Exception("You must set Where - if you want to update the whole table, set Where = new Q(true);"); sb.Append(" WHERE "); sb.Append(Where.ToString(ref paramHash, ref rankContribution)); string sql = sb.ToString(); //throw new Exception(sql); int rows = 0; SqlConnection conn; if (transaction == null) conn = new SqlConnection(Vars.DefaultConnectionString); else conn = transaction.SqlConnection; try { SqlCommand myCommand = new SqlCommand(sql, conn); if (transaction != null) myCommand.Transaction = transaction.SqlTransaction; if (CommandTimeout != -1) myCommand.CommandTimeout = CommandTimeout; foreach (string c in paramHash.Keys) { object o = paramHash[c]; myCommand.Parameters.Add(o); } if (!myCommand.Connection.State.Equals(ConnectionState.Open)) myCommand.Connection.Open(); Global.LogSqlQuery(Bobs.Global.QueryTypes.Update); rows = myCommand.ExecuteNonQuery(); } finally { if (transaction == null) { conn.Close(); conn.Dispose(); } } return rows; }
// public ThreadSet Threads // { // get // { // // TODO: Add Brand.Threads getter implementation // return null; // } // set // { // // TODO: Add Brand.Threads setter implementation // } // } #region UpdateTotalComments() public void UpdateTotalComments(Transaction transaction) { Query q = new Query(); q.TableElement = new Join( new TableElement(TablesEnum.Thread), new TableElement(TablesEnum.EventBrand), QueryJoinType.Left, Thread.Columns.EventK, EventBrand.Columns.EventK); q.QueryCondition = Brand.ThreadsQEvents(this); q.ExtraSelectElements = ForumStats.ExtraSelectElements; q.Columns = new ColumnSet(); ForumStats cs = new ForumStats(q); this.TotalComments=cs.TotalComments; this.AverageCommentDateTime=cs.AverageCommentDateTime; this.LastPost=cs.LastPost; Update(transaction); }
public void UpdateUsrCount(Transaction transaction) { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(Usr.Columns.K); q.TableElement = Usr.PhotoMeJoin; q.QueryCondition = new Q(UsrPhotoMe.Columns.PhotoK, K); q.OrderBy = new OrderBy(Usr.Columns.DateTimeSignUp); UsrSet us = new UsrSet(q); if (us.Count > 0) this.FirstUsrK = us[0].K; else this.FirstUsrK = 0; this.UsrCount = us.Count; this.Update(transaction); }
public void UpdateStats(Transaction transaction) { DataView dvCool = Db.Dv("SELECT SUM(Rating) AS theSum, COUNT(K) AS theCount FROM PhotoReview WHERE PhotoK=" + K + " AND RatingType=" + ((int)PhotoReview.RatingTypes.Cool).ToString()); int coolCount = (int)dvCool[0]["theCount"]; int coolRating = 0; double averageCool = 0; if (coolCount > 0) { coolRating = (int)dvCool[0]["theSum"]; averageCool = (double)coolRating / (double)coolCount; } double weightedCool = ((double)coolRating + 50.0) / ((double)coolCount + 10.0); DataView dvSexy = Db.Dv("SELECT SUM(Rating) AS theSum, COUNT(K) AS theCount FROM PhotoReview WHERE PhotoK=" + K + " AND RatingType=" + ((int)PhotoReview.RatingTypes.Sexy).ToString()); int sexyCount = (int)dvSexy[0]["theCount"]; int sexyRating = 0; double averageSexy = 0; if (sexyCount > 0) { sexyRating = (int)dvSexy[0]["theSum"]; averageSexy = (double)sexyRating / (double)sexyCount; } double weightedSexy = ((double)sexyRating + 50.0) / ((double)sexyCount + 10.0); double totalAverage = 0; if ((sexyCount + coolCount) > 0) totalAverage = ((double)sexyRating + (double)coolRating) / ((double)sexyCount + (double)coolCount); double totalWeightedAverage = ((double)sexyRating + (double)coolRating + 100.0) / ((double)sexyCount + (double)coolCount + 20.0); this.AverageCoolRating = averageCool; this.AverageSexyRating = averageSexy; this.TotalCoolRatings = coolCount; this.TotalSexyRatings = sexyCount; this.WeightedCoolRating = weightedCool; this.WeightedSexyRating = weightedSexy; double order = totalWeightedAverage; if (this.TotalComments > 10) order += 10.0; else order += (double)this.TotalComments; this.Order = order; this.Update(transaction); this.Gallery.UpdatePhotoOrder(transaction); }
public void UpdateStats(Transaction transaction, bool update) { Query qAll = new Query(); qAll.QueryCondition=new And(new Q(Photo.Columns.GalleryK,K),new Q(Photo.Columns.Status, QueryOperator.NotEqualTo, Photo.StatusEnum.Processing)); qAll.ReturnCountOnly=true; PhotoSet psAll = new PhotoSet(qAll); this.TotalPhotos = psAll.Count; Query qEnabled = new Query(); qEnabled.QueryCondition=new And(new Q(Photo.Columns.GalleryK,K),Photo.EnabledQueryCondition); qEnabled.ReturnCountOnly=true; PhotoSet psEnabled = new PhotoSet(qEnabled); this.LivePhotos = psEnabled.Count; if (this.TotalPhotos > this.LivePhotos) this.ModeratorUsrK = Usr.GetPhotoModeratorUsrK(); if (update) this.Update(transaction); }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; if (this.ThreadK > 0) this.Thread.DeleteAll(transaction); foreach (Thread t in this.Threads) t.DeleteAll(transaction); foreach (Para p in this.AllPara) p.DeleteAll(transaction); GallerySet gs = new GallerySet(new Query(new Q(Gallery.Columns.ArticleK,this.K))); foreach (Gallery g in gs) g.DeleteAll(transaction); Guid oldPic = this.HasPic ? this.Pic : Guid.Empty; int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0; this.Delete(transaction); if (oldPic != Guid.Empty) Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg"); if (oldPicMiscK > 0) { Misc m = new Misc(oldPicMiscK); m.DeleteAll(transaction); } }
public void UpdateTotalComments(Transaction transaction) { Query q = new Query(); q.QueryCondition = new Q(Thread.Columns.ArticleK,this.K); q.ExtraSelectElements = ForumStats.ExtraSelectElements; q.Columns = new ColumnSet(); ForumStats cs = new ForumStats(q); this.TotalComments=cs.TotalComments; this.AverageCommentDateTime=cs.AverageCommentDateTime; this.LastPost=cs.LastPost; Update(transaction); if (ParentObjectK>0 && ParentObject!=null && ParentObject is IDiscussable) ((IDiscussable)ParentObject).UpdateTotalComments(transaction); }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; if (this.ThreadK>0) this.Thread.DeleteAll(transaction); Guid oldPic = this.HasPic ? this.Pic : Guid.Empty; int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0; this.Delete(transaction); if (oldPic != Guid.Empty) Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg"); if (oldPicMiscK > 0) { Misc m = new Misc(oldPicMiscK); m.DeleteAll(transaction); } }
public void UpdateAncestorLinks(Transaction transaction) { this.UpdateAncestorLinksNoUpdate(); this.Update(transaction); }
public void UpdateTotalComments(Transaction transaction) { #region Update AverageCommentDateTime, TotalComments, HotTopicsOrder Query qStat = new Query(); qStat.QueryCondition = new Q(Comment.Columns.ThreadK, this.K); qStat.TableElement = new JoinLeft( Comment.Columns.ThreadK, Thread.Columns.K); qStat.ExtraSelectElements = ThreadStats.ExtraSelectElements; qStat.Columns = new ColumnSet(); ThreadStats tStat = new ThreadStats(qStat); this.AverageCommentDateTime = tStat.AverageCommentDateTime; this.TotalComments = tStat.CommentCount; this.HotTopicsOrder = this.AverageCommentDateTime.AddHours(this.TotalComments * 2); #endregion #region Update IndexInThread for all the comments (changed 13/03/2006 to order this by K rather than DateTime to sort problem with incorrect datetimes being set by different servers) Db.Qu(@"WITH CommentIndex_Tab AS ( SELECT *, ROW_NUMBER() OVER(ORDER BY [Comment].[K]) AS Row_Number FROM [Comment] WHERE [Comment].[ThreadK] = " + this.K.ToString() + @" ) UPDATE [CommentIndex_Tab] SET [CommentIndex_Tab].[IndexInThread] = Row_Number - 1 WHERE [CommentIndex_Tab].[ThreadK] = " + this.K.ToString() + @" AND [CommentIndex_Tab].[IndexInThread] != Row_Number - 1;"); #endregion #region Update LastPost and LastPostUsrK Query qLastComment = new Query(); qLastComment.TopRecords = 1; qLastComment.QueryCondition = new Q(Comment.Columns.ThreadK, this.K); qLastComment.OrderBy = new OrderBy(Comment.Columns.DateTime, OrderBy.OrderDirection.Descending); CommentSet cs = new CommentSet(qLastComment); if (cs.Count == 1) { this.LastPost = cs[0].DateTime; this.LastPostUsrK = cs[0].UsrK; } else { this.LastPost = this.DateTime; this.LastPostUsrK = this.UsrK; } #endregion this.Update(transaction); if (this.GroupK > 0 && this.Group != null) this.Group.UpdateTotalComments(transaction); if (!this.ParentObjectType.Equals(Model.Entities.ObjectType.Group) && this.Parent != null) this.Parent.UpdateTotalComments(transaction); }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; //delete Comments Delete CommentDelete = new Delete( TablesEnum.Comment, new Q(Comment.Columns.ThreadK, this.K) ); CommentDelete.Run(transaction); //delete ThreadUsrs Delete ThreadUsrDelete = new Delete( TablesEnum.ThreadUsr, new Q(ThreadUsr.Columns.ThreadK, this.K) ); ThreadUsrDelete.Run(transaction); //delete CommentAlerts Delete CommentAlertDelete = new Delete( TablesEnum.CommentAlert, new And( new Q(CommentAlert.Columns.ParentObjectK, this.K), new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Thread) ) ); CommentAlertDelete.Run(transaction); this.Delete(transaction); IHasPrimaryThread parentHasPrimaryThread = this.Parent as IHasPrimaryThread; if (parentHasPrimaryThread != null) parentHasPrimaryThread.UpdateSingleThread(); if (this.Parent != null) this.Parent.UpdateTotalComments(transaction); }
public void SetDisabledAndUpdate(bool disabled) { Transaction transaction = new Transaction(); try { this.Disabled = disabled; this.Update(transaction); TagPhotoHistory historyItem = new TagPhotoHistory() { Action = disabled ? TagPhotoHistory.TagPhotoHistoryAction.Disabled : TagPhotoHistory.TagPhotoHistoryAction.Enabled, DateTime = DateTime.Now, TagPhotoK = this.K, UsrK = Usr.Current.K }; historyItem.Update(transaction); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } }
public void UpdatePhotoOrder(Transaction transaction) { Query q = new Query(); q.QueryCondition=new And( Photo.EnabledQueryCondition, new Q(Photo.Columns.GalleryK,this.K) ); q.OrderBy=Photo.DateTimeOrder(OrderBy.OrderDirection.Ascending); q.NoLock=true; q.Columns=new ColumnSet( Photo.Columns.K, Photo.Columns.ContentDisabled, Photo.Columns.NextPhoto1K, Photo.Columns.NextPhoto2K, Photo.Columns.NextPhoto3K, Photo.Columns.PreviousPhoto1K, Photo.Columns.PreviousPhoto2K, Photo.Columns.PreviousPhoto3K, Photo.Columns.GalleryTimeOrder ); PhotoSet ps = new PhotoSet(q); #region declare backup vars for compare before update int bN1K = 0; int bN2K = 0; int bN3K = 0; int bP1K = 0; int bP2K = 0; int bP3K = 0; Guid bN1I = Guid.Empty; Guid bN2I = Guid.Empty; Guid bN3I = Guid.Empty; Guid bP1I = Guid.Empty; Guid bP2I = Guid.Empty; Guid bP3I = Guid.Empty; int bO = 0; #endregion for(int currentIndex=0;currentIndex<ps.Count;currentIndex++) { #region store backup vals for compare before update bN1K = ps[currentIndex].NextPhoto1K; bN2K = ps[currentIndex].NextPhoto2K; bN3K = ps[currentIndex].NextPhoto3K; bP1K = ps[currentIndex].PreviousPhoto1K; bP2K = ps[currentIndex].PreviousPhoto2K; bP3K = ps[currentIndex].PreviousPhoto3K; bO = ps[currentIndex].GalleryTimeOrder; #endregion ps[currentIndex].GalleryTimeOrder=currentIndex; for (int offset=1; offset<=3; offset++) { if (currentIndex-offset<0) { if (ps.Count+currentIndex-offset>=ps.Count || ps.Count+currentIndex-offset<0) ps[currentIndex].SetNextPrevCache(0,offset,false); else ps[currentIndex].SetNextPrevCache(ps[ps.Count+currentIndex-offset].K,offset,false); } else ps[currentIndex].SetNextPrevCache(ps[currentIndex-offset].K,offset,false); if (currentIndex+offset>=ps.Count) { if (offset-ps.Count+currentIndex>=ps.Count || offset-ps.Count+currentIndex<0) ps[currentIndex].SetNextPrevCache(0,offset,true); else ps[currentIndex].SetNextPrevCache(ps[offset-ps.Count+currentIndex].K,offset,true); } else ps[currentIndex].SetNextPrevCache(ps[currentIndex+offset].K,offset,true); } #region compare, then update if changed if ( bN1K == 0 || bN1K != ps[currentIndex].NextPhoto1K || bN2K == 0 || bN2K != ps[currentIndex].NextPhoto2K || bN3K == 0 || bN3K != ps[currentIndex].NextPhoto3K || bP1K == 0 || bP1K != ps[currentIndex].PreviousPhoto1K || bP2K == 0 || bP2K != ps[currentIndex].PreviousPhoto2K || bP3K == 0 || bP3K != ps[currentIndex].PreviousPhoto3K || bO == 0 || bO != ps[currentIndex].GalleryTimeOrder) { ps[currentIndex].Update(transaction); } #endregion } }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; PhotoSet ps = new PhotoSet(new Query(new Q(Photo.Columns.GalleryK,this.K))); foreach (Photo p in ps) p.DeleteAll(transaction); this.Delete(transaction); }
public void UpdateTotalEvents(Transaction transaction) { Query q = new Query(); q.TableElement=Event.PlaceJoin; q.QueryCondition=new Q(Place.Columns.CountryK,this.K); q.ReturnCountOnly=true; EventSet allEvents = new EventSet(q); this.TotalEvents = allEvents.Count; this.Update(transaction); }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; this.ContentDisabled = false; this.Update(transaction); try { UsrSet usPhotoPic = new UsrSet(new Query(new Q(Usr.Columns.PicPhotoK, this.K))); foreach (Usr u in usPhotoPic) { try { Guid picToDelete = u.Pic; u.Pic = Guid.Empty; u.PicPhotoK = 0; u.PicState = ""; u.Update(transaction); Storage.RemoveFromStore(Storage.Stores.Pix, picToDelete, "jpg"); } catch { } } } catch { } try { if (this.Gallery.MainPhotoK == this.K) { Query q = new Query(); q.QueryCondition = new And( new Q(Photo.Columns.GalleryK, this.GalleryK), Photo.EnabledQueryCondition ); q.OrderBy = new OrderBy(Photo.Columns.DateTime); q.Columns = new ColumnSet(Photo.Columns.K, Photo.Columns.Status); PhotoSet psMain = new PhotoSet(q); int firstDisabled = 0; foreach (Photo p in psMain) { if (p.K != this.K) { if (p.Status == StatusEnum.Enabled) { this.Gallery.MainPhotoK = p.K; break; } else if (firstDisabled == 0) firstDisabled = p.K; } } if (firstDisabled > 0) this.Gallery.MainPhotoK = firstDisabled; this.Gallery.Update(transaction); //PhotoSet psMain = new PhotoSet( // new Query( // new And( // new Q(Photo.Columns.K, QueryOperator.NotEqualTo, this.K), // new Q(Photo.Columns.GalleryK, this.GalleryK), // Photo.EnabledQueryCondition), // new OrderBy(Photo.Columns.DateTime), // 1 // ) // ); //if (psMain.Count > 0) //{ // this.Gallery.MainPhotoK = psMain[0].K; //} //else //{ // PhotoSet psMain1 = new PhotoSet( // new Query( // new And( // new Q(Photo.Columns.K, QueryOperator.NotEqualTo, this.K), // new Q(Photo.Columns.GalleryK, this.GalleryK) // ), // new OrderBy(Photo.Columns.DateTime), // 1 // ) // ); // if (psMain1.Count > 0) // { // this.Gallery.MainPhotoK = psMain1[0].K; // } // else // { // this.Gallery.MainPhotoK = 0; // } //} //this.Gallery.Update(transaction); } } catch { } try { Delete UsrPhotoFavouriteDelete = new Delete( TablesEnum.UsrPhotoFavourite, new Q(UsrPhotoFavourite.Columns.PhotoK, this.K) ); UsrPhotoFavouriteDelete.Run(transaction); } catch { } try { Delete UsrPhotoMeDelete = new Delete( TablesEnum.UsrPhotoMe, new Q(UsrPhotoMe.Columns.PhotoK, this.K) ); UsrPhotoMeDelete.Run(transaction); } catch { } try { Delete CommentAlertDelete = new Delete( TablesEnum.CommentAlert, new And( new Q(CommentAlert.Columns.ParentObjectK, this.K), new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Photo) ) ); CommentAlertDelete.Run(transaction); } catch { } try { if (this.ThreadK.HasValue && this.ThreadK.Value > 0) this.Thread.DeleteAll(transaction); } catch { } try { ThreadSet ts = new ThreadSet(new Query(new Q(Thread.Columns.PhotoK, this.K))); foreach (Thread t in ts) { t.DeleteAll(transaction); } } catch { } try { Delete PhotoReviewDelete = new Delete( TablesEnum.PhotoReview, new Q(PhotoReview.Columns.PhotoK, this.K) ); PhotoReviewDelete.Run(transaction); } catch { } try { ParaSet ps = new ParaSet(new Query(new Q(Para.Columns.PhotoK, this.K))); foreach (Para p in ps) { if (p.Type.Equals(Para.TypeEnum.Photo)) p.DeleteAll(transaction); else { Guid oldPic = p.Pic; p.Pic = Guid.Empty; p.PhotoK = 0; p.Update(transaction); if (oldPic != Guid.Empty) Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg"); } } } catch { } try { foreach (var tagPhoto in this.ChildTagPhotos()) { foreach (var tagPhotoHistory in tagPhoto.ChildTagPhotoHistorys()) { tagPhotoHistory.Delete(transaction); } tagPhoto.Delete(transaction); } } catch { } Guid uploadTemporary = this.UploadTemporary; string uploadTemporaryExtention = this.UploadTemporaryExtention; Guid master = this.Master; Guid web = this.Web; Guid thumb = this.Thumb; Guid icon = this.Icon; bool isVideo = this.MediaType == MediaTypes.Video; Guid videoMaster = this.VideoMaster; string videoFileExtention = this.VideoFileExtention; Guid videoMed = this.VideoMed; bool hasCrop = this.HasCrop; Guid crop = this.HasCrop ? this.Crop : Guid.Empty; try { this.Delete(transaction); } catch { } try { Storage.RemoveFromStore(Storage.Stores.Temporary, uploadTemporary, uploadTemporaryExtention); Storage.RemoveFromStore(Storage.Stores.Master, master, "jpg"); Storage.RemoveFromStore(Storage.Stores.Pix, web, "jpg"); Storage.RemoveFromStore(Storage.Stores.Pix, thumb, "jpg"); Storage.RemoveFromStore(Storage.Stores.Pix, icon, "jpg"); if (isVideo) { Storage.RemoveFromStore(Storage.Stores.Master, videoMaster, videoFileExtention); Storage.RemoveFromStore(Storage.Stores.Pix, videoMed, "flv"); } if (hasCrop) Storage.RemoveFromStore(Storage.Stores.Pix, crop, "jpg"); } catch { } try { this.Usr.UpdateTotalPhotos(transaction); } catch { } try { this.Gallery.UpdateStats(transaction, true); } catch { } try { this.Gallery.UpdatePhotoOrder(transaction); } catch { } try { if (this.Event != null) this.Event.UpdateTotalPhotos(transaction); } catch { } }
public void UpdateTotalComments(Transaction transaction) { // TODO: Add Country.UpdateTotalComments implementation }
public void UpdateTotalComments(Transaction transaction) { Query q = new Query(); q.QueryCondition = new And( new Q(Thread.Columns.PhotoK, this.K), new Q(Thread.Columns.Private, false), new Q(Thread.Columns.GroupPrivate, false), new Q(Thread.Columns.PrivateGroup, false) ); q.ExtraSelectElements = ForumStats.ExtraSelectElements; q.Columns = new ColumnSet(); ForumStats cs = new ForumStats(q); this.TotalComments = cs.TotalComments; this.AverageCommentDateTime = cs.AverageCommentDateTime; this.LastPost = cs.LastPost; this.UpdateStats(transaction); this.Update(transaction); if (this.Event != null) this.Event.UpdateTotalComments(transaction); if (this.Article != null) this.Article.UpdateTotalComments(transaction); }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; //Events EventSet es = new EventSet(new Query(new Q(Event.Columns.VenueK,this.K))); foreach(Event e in es) e.DeleteAll(transaction); Delete CommentAlertDelete = new Delete( TablesEnum.CommentAlert, new And( new Q(CommentAlert.Columns.ParentObjectK,this.K), new Q(CommentAlert.Columns.ParentObjectType,Model.Entities.ObjectType.Venue) ) ); CommentAlertDelete.Run(transaction); //Threads ThreadSet ts = new ThreadSet( new Query( new And( new Q(Thread.Columns.ParentObjectType,Model.Entities.ObjectType.Venue), new Q(Thread.Columns.ParentObjectK,this.K) ) ) ); foreach (Thread t in ts) t.DeleteAll(transaction); //Articles ArticleSet ars = new ArticleSet(new Query(new Q(Article.Columns.VenueK, this.K))); foreach (Article a in ars) a.DeleteAll(transaction); Guid oldPic = this.HasPic ? this.Pic : Guid.Empty; int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0; this.Delete(transaction); if (oldPic != Guid.Empty) Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg"); if (oldPicMiscK > 0) { Misc m = new Misc(oldPicMiscK); m.DeleteAll(transaction); } this.Place.UpdateTotalEvents(transaction); }
public void SetBlockedAndUpdate(bool blocked) { if (!Usr.Current.IsAdmin) { throw new Exception("You need to be an admin to block or unblock a tag"); } Transaction t = new Transaction(); Query q = new Query(new Q(TagPhoto.Columns.TagK, this.K)); List<int> tagPhotoKs = (new TagPhotoSet(q)).ToList().ConvertAll(tagPhoto => tagPhoto.K); List<Assign> changes = new List<Assign>() { new Assign(TagPhoto.Columns.Disabled, blocked) }; Q condition = new And( new Q(TagPhoto.Columns.TagK, this.K), new Q(TagPhoto.Columns.Disabled, !blocked) ); Update u = new Update(TablesEnum.TagPhoto, changes, condition); u.Run(t); foreach (int tagPhotoK in tagPhotoKs) { TagPhotoHistory historyItem = new TagPhotoHistory() { Action = blocked ? TagPhotoHistory.TagPhotoHistoryAction.Blocked : TagPhotoHistory.TagPhotoHistoryAction.Unblocked, DateTime = DateTime.Now, TagPhotoK = tagPhotoK, UsrK = Usr.Current.K }; historyItem.Update(t); } this.Blocked = blocked; this.BlockedDateTime = DateTime.Now; this.BlockedByUsrK = Usr.Current.K; this.Update(t); t.Commit(); (new Caching.CacheKeys.NamespaceCacheKey(CacheKeyPrefix.TagCloudVersion)).Invalidate(); }
partial void AfterUpdate(Transaction t) { }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; //EventBrands Delete BrandDelete = new Delete( TablesEnum.EventBrand, new Q(EventBrand.Columns.BrandK, this.K) ); BrandDelete.Run(transaction); CompSet cs = new CompSet(new Query(new Q(Comp.Columns.BrandK, this.K))); foreach (Comp c in cs) { c.BrandK = 0; c.LinkType = Comp.LinkTypes.None; c.Update(); } try { this.Group.DeleteAll(transaction); } catch { } Guid oldPic = this.HasPic ? this.Pic : Guid.Empty; int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0; this.Delete(transaction); if (oldPic != Guid.Empty) Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg"); if (oldPicMiscK > 0) { Misc m = new Misc(oldPicMiscK); m.DeleteAll(transaction); } }
public void UpdateTotalEvents(Transaction transaction) { Query q = new Query(); q.QueryCondition=new Q(Event.Columns.VenueK,this.K); q.ReturnCountOnly=true; EventSet allEvents = new EventSet(q); this.TotalEvents = allEvents.Count; this.Update(transaction); this.Place.UpdateTotalEvents(transaction); }
partial void BeforeUpdate(Transaction t) { this.DateTime = DateTime.Now; }
public void UpdateTotalComments(Transaction transaction) { Query q = new Query(); q.QueryCondition = new Q(Thread.Columns.VenueK,this.K); q.ExtraSelectElements = ForumStats.ExtraSelectElements; q.Columns = new ColumnSet(); ForumStats cs = new ForumStats(q); this.TotalComments=cs.TotalComments; this.AverageCommentDateTime=cs.AverageCommentDateTime; this.LastPost=cs.LastPost; Update(transaction); this.Place.UpdateTotalComments(transaction); }
public int Run(Transaction transaction) { Dictionary<string, SqlParameter> paramHash = new Dictionary<string, SqlParameter>(); string rankContribution = ""; string sql = "DELETE FROM [" + Tables.GetTableName(From) + "] WHERE " + Where.ToString(ref paramHash, ref rankContribution); int rows = 0; SqlConnection conn; if (transaction == null) conn = new SqlConnection(Vars.DefaultConnectionString); else conn = transaction.SqlConnection; try { SqlCommand myCommand = new SqlCommand(sql, conn); if (CommandTimeout != -1) myCommand.CommandTimeout = CommandTimeout; if (transaction != null) myCommand.Transaction = transaction.SqlTransaction; foreach (string c in paramHash.Keys) { object o = paramHash[c]; myCommand.Parameters.Add(o); } if (!conn.State.Equals(System.Data.ConnectionState.Open)) conn.Open(); Bobs.Global.LogSqlQuery(Bobs.Global.QueryTypes.Delete); rows = myCommand.ExecuteNonQuery(); } finally { if (transaction == null) { conn.Close(); conn.Dispose(); } } return rows; }
public void DeleteAll(Transaction transaction) { if (!this.Bob.DbRecordExists) return; this.Delete(transaction); this.Usr.UpdateBuddyCount(transaction); this.BuddyUsr.UpdateBuddyCount(transaction); }