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 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(); } }
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 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 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(); } }