private void sendEmailOnReply() { string userEmail = string.Empty; string ticketBody = "\n\n" + FromUsername + ":\n" + Body; ticketBody += "\n\n-------------------------------------\n\n"; using (var br = ParserPool.Acquire(Database.Client)) { var where = TableHelper.MakeDictionary(Member.Columns.Username, FromUsername); userEmail = br.Instance.Select(Member.TableName, Member.Columns.Email, where) as string; var querry = string.Format(@"SELECT * FROM {0} WHERE {1} = {2} ORDER BY {3} ASC", SupportTicketReply.TableName, SupportTicketReply.Columns.TicketId, Id, SupportTicketReply.Columns.ReplyDate); var tickets = TableHelper.GetListFromRawQuery <SupportTicketReply>(querry); for (int i = 0; i < tickets.Count - 1; i++) { ticketBody += AddTicketResponseToEmailBody(tickets[i]); } ticketBody += AddTicketResponseToEmailBody(tickets.Last(), false); } string subject = "Ticket response"; Mailer.SendEmailToUser(userEmail, subject, ticketBody); }
/// <summary> /// Selects values from database with apropriate rowId /// </summary> /// <param name="id"></param> /// <exception cref="DbException" /> protected BaseTableObject(int id) { using (var bridge = ParserPool.Acquire(Database)) { Id = id; DataRow row; row = bridge.Instance.Select(dbTable, IdDictionary).Rows[0]; SetColumnsFromDataRow(row, true); } }
private void reloadPartially(bool isUpToDate, StringCollection columnPropertiesToReload) { if (IsInDatabase) { using (var bridge = ParserPool.Acquire(Database)) { DataRow objectRow = bridge.Instance.Select(dbTable, columnPropertiesToReload, IdDictionary).Rows[0]; SetColumnsFromDataRow(objectRow, isUpToDate); } } else { throw new InvalidOperationException("Object not in database"); } }
/// <summary> /// Removes current instance of class from database /// but doesn't affect this object /// </summary> /// <exception cref="DbException"/> public virtual void Delete() { OnPreDelete(EventArgs.Empty); if (IsInDatabase) { using (var bridge = ParserPool.Acquire(Database)) { bridge.Instance.Delete(dbTable, IdDictionary); Id = NotInDatabaseId; } } IsUpToDate = false; }
/// <summary> /// Saves part of object in database specified by columnPropertiesToSave. /// Can be used only when object IsInDatabase (otherwise throws an exception). /// If !IsInDatabase Use Save() instead. /// </summary> /// <param name="isUpToDate">You must explicitly set whether after /// partial save all columns are up to date, if you are not positive set false</param> /// <param name="columnPropertiesToSave"></param> protected void SavePartially(bool isUpToDate, params PropertyInfo[] columnPropertiesToSave) { if (!IsInDatabase) { throw new InvalidOperationException("Object must be saved in datbase. Use Save()"); } if (IsInDatabase && !IsUpToDate) { using (var bridge = ParserPool.Acquire(Database)) { bridge.Instance.Update(dbTable, GetColumnsDictionary(columnPropertiesToSave), IdDictionary); IsUpToDate = isUpToDate; } } }
/// <summary> /// Downloads object from database and sets its contents with downloaded values. /// </summary> /// <exception cref="DbException" /> public virtual void Reload() { OnPreReload(EventArgs.Empty); if (IsInDatabase) { using (var bridge = ParserPool.Acquire(Database)) { DataRow objectRow = bridge.Instance.Select(dbTable, IdDictionary).Rows[0]; SetColumnsFromDataRow(objectRow, IsUpToDate); IsUpToDate = true; } } else { throw new InvalidOperationException("Object not in database"); } }
/// <summary> /// Saves current instance in database. <br /> /// Performs: Insert (when object is not already in database), /// Update (when is already in database and !IsUpToDate), /// or nothing (when IsUpToDate); /// </summary> /// <param name="forceSave">if true, saves even if object IsUpToDate</param> /// <exception cref="DbException" /> public virtual void Save(bool forceSave = false) { OnPreSave(EventArgs.Empty); if (IsInDatabase && IsUpToDate && !forceSave) { return; } using (var bridge = ParserPool.Acquire(Database)) { if (!IsInDatabase) { bridge.Instance.Insert(dbTable, getQueryDictionary(forceSave)); getIdJustAfterInserting(bridge.Instance); } else if (IsInDatabase && (!IsUpToDate || forceSave)) { bridge.Instance.Update(dbTable, getQueryDictionary(forceSave), IdDictionary); } IsUpToDate = true; } }
public void Dispose() { ParserPool.Release(Instance); }