public List<Chat> GetPublicChats() { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetAllPublicChats(); } }
public List<Chat> GetAllChatsForUser(User u) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetAllChatsForUserId(u.Id); } }
public Chat GetChatById(int chatId) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetChatById(chatId); } }
/// <summary> /// Returns a user from the db with the given Id /// </summary> /// <param name="userId"></param> /// <returns></returns> public User GetUserWithId(int userId) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetUserById(userId); } }
/// <summary> /// Returns the user that has the same username and password given. /// throws ArgumentNull exception and Invalid Username Exception /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public static User GetUserWithUsernameAndPassword(string userName, string password) { if (string.IsNullOrEmpty(userName)) { throw new System.ArgumentNullException(nameof(userName)); } if (string.IsNullOrEmpty(password)) { throw new System.ArgumentNullException(nameof(password)); } using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { Guid? guid = query.GetGuidByUserName(userName); if (!guid.HasValue) { throw new InvalidUserNameException("Couldn't get Guid", userName); } string hashedPassword = CreateHashedPassword(password, guid.Value); User u = query.GetUserByUserNameAndPasswordHash(userName, hashedPassword); if (u == null) { throw new InvalidUserNameAndPasswordException("User was not found", userName); } return u; } }
public User GetUserWithUserName(string username) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetUserByUserName(username); } }
public List<Message> GetAllMessagesForChat(int chatId) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.GetMessagesByChatId(chatId); } }
public Chat AddChat(Chat c) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { query.AddChat(c); Chat newChat = query.GetChatByNameAndDateCreated(c.Name, c.DateCreated); return (newChat != null) ? newChat : null; } }
/// <summary> /// Adds the message to the db and returns it if it succeeds in adding it /// </summary> /// <param name="m"></param> /// <returns></returns> public Message AddMessage(Message m) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { query.AddMessage(m); Message addedMessage = query.GetMessageByUserAndDate(m.UserId, m.DateCreated); return (addedMessage != null) ? addedMessage : null; } }
public void AddUserTest02() { using (PexDisposableContext disposables = PexDisposableContext.Create()) { SportsChatQueries sportsChatQueries; sportsChatQueries = new SportsChatQueries((SportsChatEntities)null); disposables.Add((IDisposable)sportsChatQueries); this.AddUserTest(sportsChatQueries, (User)null); disposables.Dispose(); } }
/// <summary> /// Creates a user with all of the given parameters /// Returns the id of the user created /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="emailAddress"></param> public int CreateNewUser(string userName, string password, string firstName, string lastName, string emailAddress) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { if (query.UserNameExists(userName)) { throw new InvalidUserNameException("Username is already taken"); } return UserFactory.CreateNewUser(userName, password, emailAddress, firstName, lastName); } }
public bool DeleteMessage(Message m) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { Message messageToDelete = query.GetMessageById(m.Id); if (messageToDelete != null) { query.RemoveMessage(messageToDelete); return true; } } return false; }
/// <summary> /// Creates a New User and adds that user to the db /// Returns the id of the User created /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> public static int CreateNewUser(string userName, string password, string email, string firstName, string lastName) { User u = new User() { UserName = userName, EmailAddress = email, FirstName = firstName, LastName = lastName }; u.Guid = NewGuid(); u.Password = CreateHashedPassword(password, u.Guid); using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { query.AddUser(u); User created = query.GetUserByUserNameAndPasswordHash(u.UserName, u.Password); if (created == null) { return 0; } return created.Id; } }
internal SportsChatQueries ConstructorTest01(SportsChatEntities _ctx) { SportsChatQueries target = new SportsChatQueries(_ctx); return target; // TODO: add assertions to method SportsChatQueriesTest.ConstructorTest01(SportsChatEntities) }
/// <summary> /// Updates the User in the db to the one passed in. /// </summary> /// <param name="u"></param> public void UpdateUser(User u) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { query.UpdateUser(u); } }
/// <summary> /// Lets you know if the username exists in the db /// </summary> /// <param name="username"></param> /// <returns></returns> public bool UserNameValid(string username) { using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities())) { return query.UserNameExists(username); } }