示例#1
0
        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);
                }
            }
        }
示例#2
0
        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());
            }
        }
示例#3
0
        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();

            }
        }
示例#4
0
        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();
            }
        }
示例#6
0
        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();
            }
        }
示例#7
0
        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 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;
            }
        }
示例#10
0
        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);
            }
        }
示例#11
0
        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;
            }
        }
示例#12
0
        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());
            }
        }
示例#13
0
        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();
            }
        }
示例#14
0
        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);
            }
        }
示例#15
0
        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;
            }
        }
示例#16
0
        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;
                }
            }
        }