public List <IForumPost> GetForumPosts(int threadID) { List <IForumPostDto> forumPostDtos = db.GetForumPosts(threadID); foreach (var forumPostDto in forumPostDtos) { IAccountDto accountDto = accountdb.GetAccount(forumPostDto.AccountID); IAccount account = new Account(DataHandlerFactory.DataHandlerFactory.GetAccountContext()) { AccountID = accountDto.AccountID, Username = accountDto.Username, Email = accountDto.Email, Password = accountDto.Password, Role = accountDto.Role, ProfilePicture = accountDto.ProfilePicture, DateJoined = accountDto.DateJoined, }; forumPosts.Add(new ForumPost(DataHandlerFactory.DataHandlerFactory.GetForumPostContext()) { PostID = forumPostDto.PostID, ThreadID = forumPostDto.ThreadID, AccountID = forumPostDto.AccountID, PostMessage = forumPostDto.PostMessage, PostDateCreated = forumPostDto.PostDateCreated, Account = account }); } return(forumPosts); }
private static AccountRepresentation RepresentAccount(IAccountDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } return(new AccountRepresentation(dto.Id, (AccountGrade)dto.Type, dto.Owner, dto.Balance, dto.Bonus)); }
public bool LoginQuery(string username, string password) { IAccountDto accountDto = db.GetAccount(username); if (username == accountDto.Username && password == accountDto.Password) { return(true); } else { return(false); } }
/// <inheritdoc/> public void AddRecord(IAccountDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } if (this.storage.ContainsKey(dto.Id)) { throw new ArgumentException($"ID '{dto.Id}' already exists."); } this.storage.Add(dto.Id, dto); }
/// <inheritdoc/> public void UpdateRecord(IAccountDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } if (!this.storage.ContainsKey(dto.Id)) { throw new ArgumentException($"No such ID: '{dto.Id}'."); } this.storage.Remove(dto.Id); this.storage.Add(dto.Id, dto); }
public IAccount GetAccount(int accountID) { IAccountDto accountDto = db.GetAccount(accountID); IAccount account = new Account(DataHandlerFactory.DataHandlerFactory.GetAccountContext()) { AccountID = accountDto.AccountID, DateJoined = accountDto.DateJoined, Email = accountDto.Email, Password = accountDto.Password, ProfilePicture = accountDto.ProfilePicture, Role = accountDto.Role, Username = accountDto.Username, }; return(account); }
/// <inheritdoc/> public void AddRecord(IAccountDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } var record = new AccountRecord() { Id = dto.Id, Type = dto.Type, Owner = dto.Owner, Balance = dto.Balance, Bonus = dto.Bonus, }; using (var db = new AccountContext()) { db.AccountSet.Add(record); db.SaveChanges(); } }
/// <inheritdoc/> public void UpdateRecord(IAccountDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } using (var db = new AccountContext()) { var record = db.AccountSet.Find(dto.Id); if (record is null) { throw new ArgumentException($"No such ID: '{dto.Id}'."); } record.Type = dto.Type; record.Owner = dto.Owner; record.Balance = dto.Balance; record.Bonus = dto.Bonus; db.SaveChanges(); } }