public bool RegisterUserForEvent(int eventId, int userId) { using (var db = new EventSignInEntities()) { if (db.EventAttendances.Any(e => e.EventId == eventId && e.UserId == userId)) { return(true); // Already registered. } try { db.EventAttendances.Add(new EventAttendance { EventId = eventId, UserId = userId, }); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public IList <EventModel> GetEventsForUser(int userId) { using (var db = new EventSignInEntities()) { var categories = _categoryDataAccess.GetCategories() .ToDictionary(c => c.Id, c => c); var users = _userDataAccess.GetUsers() .ToDictionary(u => u.Id, u => u); var events = db.Events .Where(e => e.EventAttendances.Any(ea => ea.UserId == userId)) .ToList(); return(events.Select(e => new EventModel { Id = e.Id, Name = e.Name, Description = e.Description, Location = e.Location, Date = e.Date, Category = categories[e.Category], Attendees = e.EventAttendances.Select(user => users[user.UserId]) .ToList(), }) .ToList()); } }
public IList<EventModel> GetEventsForUser(int userId) { using (var db = new EventSignInEntities()) { var categories = _categoryDataAccess.GetCategories() .ToDictionary(c => c.Id, c => c); var users = _userDataAccess.GetUsers() .ToDictionary(u => u.Id, u => u); var events = db.Events .Where(e => e.EventAttendances.Any(ea => ea.UserId == userId)) .ToList(); return events.Select(e => new EventModel { Id = e.Id, Name = e.Name, Description = e.Description, Location = e.Location, Date = e.Date, Category = categories[e.Category], Attendees = e.EventAttendances.Select(user => users[user.UserId]) .ToList(), }) .ToList(); } }
public IList <CategoryModel> GetCategories() { using (var db = new EventSignInEntities()) { var categories = db.Categories .Select(category => new CategoryModel { Id = category.Id, Name = category.Name, Description = category.Description, }); return(categories.ToList()); } }
public IList<CategoryModel> GetCategories() { using (var db = new EventSignInEntities()) { var categories = db.Categories .Select(category => new CategoryModel { Id = category.Id, Name = category.Name, Description = category.Description, }); return categories.ToList(); } }
public void UpdateCategory(CategoryModel category) { using (var db = new EventSignInEntities()) { var dbCategory = db.Categories.FirstOrDefault(c => c.Id == category.Id); if (dbCategory == null) { throw new InvalidOperationException(string.Format("Could not find Category with ID: {0}", category.Id)); } dbCategory.Name = category.Name; dbCategory.Description = category.Description; db.SaveChanges(); } }
public int AddCategory(CategoryModel category) { using (var db = new EventSignInEntities()) { var newCategory = new Category { Name = category.Name, Description = category.Description }; db.Categories.Add(newCategory); db.SaveChanges(); return(newCategory.Id); } }
public int AddCategory(CategoryModel category) { using (var db = new EventSignInEntities()) { var newCategory = new Category { Name = category.Name, Description = category.Description }; db.Categories.Add(newCategory); db.SaveChanges(); return newCategory.Id; } }
public int CreateEvent(EventModel e) { using (var db = new EventSignInEntities()) { var newEvent = new Event { Name = e.Name, Description = e.Description, Location = e.Location, Date = e.Date, Category = e.Category.Id, }; db.Events.Add(newEvent); db.SaveChanges(); return(newEvent.Id); } }
public int CreateEvent(EventModel e) { using (var db = new EventSignInEntities()) { var newEvent = new Event { Name = e.Name, Description = e.Description, Location = e.Location, Date = e.Date, Category = e.Category.Id, }; db.Events.Add(newEvent); db.SaveChanges(); return newEvent.Id; } }
public IList <UserModel> GetUsers() { using (var db = new EventSignInEntities()) { var users = db.Users .Select(user => new UserModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, EmailOptIn = user.EmailOptIn, GraduationYear = user.GraduationYear, Notes = user.Notes, PhoneNumber = user.PhoneNumber, }); return(users.ToList()); } }
public IList<UserModel> GetUsers() { using (var db = new EventSignInEntities()) { var users = db.Users .Select(user => new UserModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, EmailOptIn = user.EmailOptIn, GraduationYear = user.GraduationYear, Notes = user.Notes, PhoneNumber = user.PhoneNumber, }); return users.ToList(); } }
public int CreateUser(UserModel user) { using (var db = new EventSignInEntities()) { var newUser = new User { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, EmailOptIn = true, // All users should be opted in by default at creation GraduationYear = user.GraduationYear, Notes = user.Notes, PhoneNumber = user.PhoneNumber, }; db.Users.Add(newUser); db.SaveChanges(); return(newUser.Id); } }
public int CreateUser(UserModel user) { using (var db = new EventSignInEntities()) { var newUser = new User { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, EmailOptIn = true, // All users should be opted in by default at creation GraduationYear = user.GraduationYear, Notes = user.Notes, PhoneNumber = user.PhoneNumber, }; db.Users.Add(newUser); db.SaveChanges(); return newUser.Id; } }
public bool RegisterUserForEvent(int eventId, int userId) { using (var db = new EventSignInEntities()) { if (db.EventAttendances.Any(e => e.EventId == eventId && e.UserId == userId)) { return true; // Already registered. } try { db.EventAttendances.Add(new EventAttendance { EventId = eventId, UserId = userId, }); db.SaveChanges(); return true; } catch (Exception) { return false; } } }