public void UpdateCommunityNewsCount(dtoCommunityWithNews previous) { CommunityNewsSummary reminder = null; using (ISession session = NHSessionHelper.GetSession()) { try { session.BeginTransaction(); reminder = (from CommunityNewsSummary r in session.Linq <CommunityNewsSummary>() where r.PersonID == previous.PersonID && r.CommunityID == previous.CommunityID orderby r.CommunityID select r).FirstOrDefault <CommunityNewsSummary>(); if (reminder != null) { if (previous.LastUpdate == null || previous.LastUpdate == new DateTime()) { reminder.ActionCount = 0; } else if (previous.LastUpdate == reminder.LastUpdate) { reminder.ActionCount = 0; } else if (previous.ActionCount < reminder.ActionCount) { reminder.ActionCount = reminder.ActionCount - previous.ActionCount; } reminder.LastUpdate = DateTime.Now; session.SaveOrUpdate(reminder); session.CommitTransaction(); } } catch (Exception ex) { if (session.isInTransaction()) { session.RollbackTransaction(); } } } }
public static bool Save(CommunityNewsSummary reminder) { Database oDatabase = DatabaseFactory.CreateDatabase(DataHelpers.ConnectionString()); using (DbConnection connection = oDatabase.CreateConnection()) { connection.Open(); try { DbCommand oCommand; if (reminder.ID == System.Guid.Empty) { oCommand = oDatabase.GetStoredProcCommand("sp_CommunityNewsSummaryRepository_Add"); reminder.ID = System.Guid.NewGuid(); } else { oCommand = oDatabase.GetStoredProcCommand("sp_CommunityNewsSummaryRepository_Update"); } oDatabase.AddInParameter(oCommand, "@CommunityID", System.Data.DbType.Int64, reminder.CommunityID); oDatabase.AddInParameter(oCommand, "@CountAction", System.Data.DbType.Int64, reminder.ActionCount); oDatabase.AddInParameter(oCommand, "@PersonID", System.Data.DbType.Int64, reminder.PersonID); oDatabase.AddInParameter(oCommand, "@ID", System.Data.DbType.Guid, reminder.ID); oCommand.Connection = connection; if (oCommand.ExecuteNonQuery() == 1) { return(true); } else { return(false); } } catch (Exception ex) { System.Diagnostics.EventLog.WriteEntry("CommunityNewsSummaryRepository", ex.Message); return(false); } } }