示例#1
0
        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);
            }
        }
示例#2
0
 public IEnumerable <UserBO> GetNonParticipatingUsersById(int contest_id)
 {
     using (var context = new aspnet_learningEntities())
     {
         var repository = new UserRepository(context);
         return(repository.GetNonParticipatingUsersById(contest_id));
     }
 }
示例#3
0
 public string GetAliasByUser(int userId)
 {
     using (var context = new aspnet_learningEntities())
     {
         var repository = new UserRepository(context);
         return(repository.GetUserById(userId)?.alias);
     }
 }
示例#4
0
 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();
     }
 }
示例#5
0
 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();
         }
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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();
         }
     }
 }
示例#8
0
 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();
     }
 }
示例#9
0
 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();
     }
 }
示例#10
0
        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)));
            }
        }
示例#11
0
        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();
            }
        }
示例#12
0
 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);
     }
 }
示例#13
0
        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();
            }
        }
示例#14
0
        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)));
            }
        }
示例#15
0
        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()
                }
                                                  )));
            }
        }
示例#16
0
 public ContestRepository(aspnet_learningEntities context)
 {
     this._context = context;
 }