public static void AddSubscription(LoginUser loginUser, int userID, ReferenceType refType, int refID) { if (IsUserSubscribed(loginUser, userID, refType, refID)) { return; } Subscriptions subscriptions = new Subscriptions(loginUser); using (SqlCommand command = new SqlCommand()) { command.CommandText = "INSERT INTO Subscriptions (RefType, RefID, UserID, DateCreated, DateModified, CreatorID, ModifierID) VALUES (@RefType, @RefID, @UserID, @DateCreated, @DateModified, @CreatorID, @ModifierID)"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@UserID", userID); command.Parameters.AddWithValue("@RefID", refID); command.Parameters.AddWithValue("@RefType", (int)refType); command.Parameters.AddWithValue("@DateCreated", DateTime.UtcNow); command.Parameters.AddWithValue("@DateModified", DateTime.UtcNow); command.Parameters.AddWithValue("@CreatorID", loginUser.UserID); command.Parameters.AddWithValue("@ModifierID", loginUser.UserID); subscriptions.ExecuteNonQuery(command, "Subscriptions,Tickets,Users"); } string description = "Subscribed '" + Users.GetUserFullName(loginUser, userID) + "' to "; if (refType == ReferenceType.Tickets) { Ticket ticket = (Ticket)Tickets.GetTicket(loginUser, refID); description = description + Tickets.GetTicketLink(ticket); } ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, refType, refID, description); ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Users, userID, description); }
public static void RemoveSubscription(LoginUser loginUser, int userID, ReferenceType refType, int refID) { Subscriptions subscriptions = new Subscriptions(loginUser); using (SqlCommand command = new SqlCommand()) { command.CommandText = "DELETE FROM Subscriptions WHERE (RefType = @RefType) AND (RefID = @RefID) AND (UserID = @UserID)"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@UserID", userID); command.Parameters.AddWithValue("@RefType", (int)refType); command.Parameters.AddWithValue("@RefID", refID); subscriptions.ExecuteNonQuery(command, "Subscriptions,Tickets,Users"); } string description = "Unsubscribed '" + Users.GetUserFullName(loginUser, userID) + "' from "; if (refType == ReferenceType.Tickets) { Ticket ticket = (Ticket)Tickets.GetTicket(loginUser, refID); description = description + Tickets.GetTicketLink(ticket); } ActionLogs.AddActionLog(loginUser, ActionLogType.Delete, refType, refID, description); ActionLogs.AddActionLog(loginUser, ActionLogType.Delete, ReferenceType.Users, userID, description); }