public IEnumerable <UserBO> GetAllUsers() { using (var context = new aspnet_learningEntities()) { var repository = new UserRepository(context); var rawUsers = repository.GetAllUsers(); var userBos = rawUsers.Select(u => { var user = new UserBO(u.id, u.alias, u.first_name, u.last_name, u.registration_date); var contestParticipantBos = u.contest_participations.Select(c => new ContestParticipantBO { Placement = c.placement, Score = c.score, User = user, Contest = new ContestBO { Id = c.contest_id } }).ToList(); user.Participations = contestParticipantBos; return(user); }).ToList(); return(userBos); } }
public IEnumerable <UserBO> GetNonParticipatingUsersById(int contest_id) { using (var context = new aspnet_learningEntities()) { var repository = new UserRepository(context); return(repository.GetNonParticipatingUsersById(contest_id)); } }
public string GetAliasByUser(int userId) { using (var context = new aspnet_learningEntities()) { var repository = new UserRepository(context); return(repository.GetUserById(userId)?.alias); } }
public void NewUser(UserBO user) { using (var context = new aspnet_learningEntities()) { var rawUser = new users() { alias = user.Alias, first_name = user.FirstName, last_name = user.LastName, registration_date = DateTime.Now }; context.users.Add(rawUser); context.SaveChanges(); } }
internal void DeleteUser(int id) { using (var context = new aspnet_learningEntities()) { var rawUser = context.users.SingleOrDefault(u => u.id == id); if (rawUser != null) { context.users.Remove(rawUser); context.SaveChanges(); } } }
public UserBO GetUserById(int userId) { using (var context = new aspnet_learningEntities()) { var repository = new UserRepository(context); var DALUser = repository.GetUserById(userId); var user = DALUser != null ? new UserBO(DALUser.id, DALUser.alias, DALUser.first_name, DALUser.last_name, DALUser.registration_date) : null; return(user); } }
public void UpdateUser(UserBO user) { using (var context = new aspnet_learningEntities()) { var rawUser = context.users.SingleOrDefault(u => u.id == user.Id); if (rawUser != null) { rawUser.alias = user.Alias; rawUser.first_name = user.FirstName; rawUser.last_name = user.LastName; context.SaveChanges(); } } }
public void AddParticipation(ContestParticipantBO participant) { using (var context = new aspnet_learningEntities()) { var rawCP = new contest_participations() { user_id = participant.User.Id, contest_id = participant.Contest.Id, score = participant.Score, placement = participant.Placement }; context.contest_participations.Add(rawCP); context.SaveChanges(); } }
public void NewContest(ContestBO contest) { using (var context = new aspnet_learningEntities()) { var rawContest = new contests() { name = contest.Name, food_item = contest.FoodItem, location = contest.Location, date = contest.Date }; context.contests.Add(rawContest); context.SaveChanges(); } }
public IEnumerable <ContestBO> GetAllContests() { using (var context = new aspnet_learningEntities()) { var repository = new ContestRepository(context); var contests = repository.GetAllContests(); return(contests.Select(c => new ContestBO( c.id, c.name, c.food_item, c.location, c.date ?? new DateTime(), c.contest_participations.ToList().Count))); } }
public void DeleteContestById(int contestId) { using (var context = new aspnet_learningEntities()) { var rawCp = context.contest_participations.Where(cp => cp.contest_id == contestId); var rawCon = context.contests.SingleOrDefault(c => c.id == contestId); if (rawCon == null) { throw new NullReferenceException("The contest you tried to delete does not exist"); } context.contest_participations.RemoveRange(rawCp); context.contests.Remove(rawCon); context.SaveChanges(); } }
public ContestBO GetContestById(int contestId) { using (var context = new aspnet_learningEntities()) { var repository = new ContestRepository(context); var DALContest = repository.GetContestById(contestId); var contest = DALContest != null ? new ContestBO( DALContest.id, DALContest.name, DALContest.food_item, DALContest.location, DALContest.date ?? new DateTime(), DALContest.contest_participations.Count) : null; return(contest); } }
public void UpdateContest(ContestBO contest) { using (var context = new aspnet_learningEntities()) { var rawCon = context.contests.SingleOrDefault(c => c.id == contest.Id); if (rawCon == null) { throw new NullReferenceException("The contest you tried to update does not exist"); } rawCon.name = contest.Name; rawCon.food_item = contest.FoodItem; rawCon.location = contest.Location; rawCon.date = contest.Date; context.SaveChanges(); } }
public IEnumerable <ContestParticipantBO> GetParticipantsFromContestById(int contestId) { using (var context = new aspnet_learningEntities()) { var repository = new ContestRepository(context); var rawParticipants = repository.GetParticipantsFromContestById(contestId); return(rawParticipants.Select(cp => new ContestParticipantBO( cp.score, cp.placement, new UserBO( cp.users.id, cp.users.alias, cp.users.first_name, cp.users.last_name, cp.users.registration_date), null))); } }
public IEnumerable <ContestParticipantBO> GetContestsByUserId(int userId) { using (var context = new aspnet_learningEntities()) { var repository = new UserRepository(context); var rawParticipants = repository.GetContestsByUserId(userId); return(rawParticipants.Select(cp => new ContestParticipantBO( cp.score, cp.placement, null, new ContestBO { Id = cp.contest_id, Name = cp.contests.name, FoodItem = cp.contests.food_item, Location = cp.contests.location, Date = cp.contests.date ?? new DateTime() } ))); } }
public ContestRepository(aspnet_learningEntities context) { this._context = context; }