Esempio n. 1
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="facebookId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IRegisteredUserRepository"/></returns>
 public RegisteredUser Get(string facebookId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.RegisteredUsers.FirstOrDefault(q => q.FacebookId.Equals(facebookId, StringComparison.OrdinalIgnoreCase)));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="sessionId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IMaterialRepository"/></returns>
 public IList<Material> GetAll(int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         return context.Materials.Where(q => q.SessionId == sessionId).ToList();
     }
 }
        /// <summary>
        /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
        /// </summary>
        /// <param name="organizerId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
        /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
        public IList <Speaker> GetTopSpeakers(int organizerId)
        {
            using (var context = new MyEventsContext())
            {
                var result = context.Sessions
                             .Include("EventDefinition")
                             .Include("SessionRegisteredUsers")
                             .Where(s => s.EventDefinition.OrganizerId == organizerId)
                             .Select(ru => new Speaker()
                {
                    Name  = ru.Speaker,
                    Score =
                        ru.SessionRegisteredUsers.Any(sru => sru.Rated)
                            ? ru.SessionRegisteredUsers.Where(sru => sru.Rated).Average(sru => sru.Score) : 0
                })
                             .GroupBy(s => s.Name)
                             .Select(g => new Speaker()
                {
                    Name = g.Key, Score = g.Average(s => s.Score)
                })
                             .OrderByDescending(ru => ru.Score)
                             .Take(5)
                             .ToList();

                return(result);
            }
        }
Esempio n. 4
0
 /// <summary> 
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="commentId"><see cref="MyEvents.Data.ICommentRepository"/></param>
 /// <returns></returns>
 public Comment Get(int commentId)
 {
     using (var context = new MyEventsContext())
     {
         return context.Comments.Single(q => q.CommentId == commentId);
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public int GetCount()
 {
     using (var context = new MyEventsContext())
     {
         return(context.EventDefinitions.Count());
     }
 }
Esempio n. 6
0
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public IList<Session> GetAllWithUserInfo(int registeredUserId, int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return context.Sessions.Include("SessionRegisteredUsers")
             .Where(q => q.EventDefinitionId == eventDefinitionId)
             .ToList()
             .Select(q => new Session()
             {
                 SessionId = q.SessionId,
                 Title = q.Title,
                 Description = q.Description,
                 Speaker = q.Speaker,
                 Biography = q.Biography,
                 StartTime = q.StartTime,
                 Duration = q.Duration,
                 RoomNumber = q.RoomNumber,
                 AttendeesCount = q.SessionRegisteredUsers.Count(),
                 TwitterAccount = q.TwitterAccount,
                 TimeZoneOffset = q.TimeZoneOffset,
                 EventDefinitionId = q.EventDefinitionId,
                 IsFavorite = q.SessionRegisteredUsers.Any(sr => sr.RegisteredUserId == registeredUserId),
                 UserScore = q.SessionRegisteredUsers.Any(sr => sr.RegisteredUserId == registeredUserId) ?
                         q.SessionRegisteredUsers.First(sr => sr.RegisteredUserId == registeredUserId).Score : 0,
                 Score = q.SessionRegisteredUsers.Any(sr => sr.Rated) ?
                         q.SessionRegisteredUsers.Where(sr => sr.Rated).Average(sr => sr.Score) : 0
             }).ToList();
     }
 }
Esempio n. 7
0
        /// <summary>
        /// <see cref="MyEvents.Data.ICommentRepository"/>
        /// </summary>
        /// <param name="sessionId"><see cref="MyEvents.Data.ICommentRepository"/></param>
        /// <returns><see cref="MyEvents.Data.ICommentRepository"/></returns>
        public IList<Comment> GetAll(int sessionId)
        {
            using (var context = new MyEventsContext())
            {
                return context.Comments.Include("registeredUser")
                    .Where(q => q.SessionId == sessionId)
                    .OrderByDescending(c => c.AddedDateTime)
                    .ToList()
                    .Select(c => new Comment()
                    {
                        CommentId = c.CommentId,
                        SessionId = c.SessionId,
                        Text = c.Text,
                        AddedDateTime = c.AddedDateTime,
                        RegisteredUserId = c.RegisteredUserId,
                        RegisteredUser = new RegisteredUser()
                        {
                            RegisteredUserId = c.RegisteredUserId,
                            Name = c.RegisteredUser.Name,
                        }
                    })
                    .ToList();

            }
        }
Esempio n. 8
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="sessionId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IMaterialRepository"/></returns>
 public IList <Material> GetAll(int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.Materials.Where(q => q.SessionId == sessionId).ToList());
     }
 }
        public void AddRegisteredUserToEvent_Integration_CallWebAPI_RegisteredUserAdded_NotFail_Test()
        {
            int registeredUserId = 0;
            int eventDefinitionId = 0;
            int expected = 0;
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            // Get values to test
            using (var context = new MyEventsContext())
            {
                registeredUserId = context.RegisteredUsers.First().RegisteredUserId;
                var eventDefinition = context.EventDefinitions.Include("RegisteredUsers")
                    .Where(e => !e.RegisteredUsers.Any(r => r.RegisteredUserId == registeredUserId)).First();
                eventDefinitionId = eventDefinition.EventDefinitionId;
                expected = eventDefinition.RegisteredUsers.Count() + 1;
            }

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();
            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(registeredUserId));
            IAsyncResult ar = service.RegisteredUserService.AddRegisteredUserToEventAsync(registeredUserId, eventDefinitionId, (HttpStatusCode statusCode) =>
            {
                // Asserts
                using (var context = new MyEventsContext())
                {
                    var eventDefinition = context.EventDefinitions.Include("RegisteredUsers").First(e => e.EventDefinitionId == eventDefinitionId);
                    int actual = eventDefinition.RegisteredUsers.Count();
                    TestHelper.ValidateResult(expected, actual, manualResetEvent, ref exceptionResult);
                }
            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
Esempio n. 10
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IRegisteredUserRepository"/></returns>
 public RegisteredUser GetById(int registeredUserId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.RegisteredUsers.FirstOrDefault(q => q.RegisteredUserId == registeredUserId));
     }
 }
Esempio n. 11
0
        public void DeleteRoomPoints_CallWebAPI_NotFail_Test()
        {
            var context = new MyEventsContext();
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            var eventDefinition = context.EventDefinitions.First();
            int roomNumber = 20;
            context.RoomPoints.Add(new RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 0, PointY = 0, RoomNumber = roomNumber });
            context.RoomPoints.Add(new RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 0, PointY = 0, RoomNumber = roomNumber });
            context.RoomPoints.Add(new RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 0, PointY = 0, RoomNumber = roomNumber });

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();
            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(eventDefinition.OrganizerId));
            IAsyncResult asynResult = service.RoomPointService.DeleteRoomPointsAsync(eventDefinition.EventDefinitionId, roomNumber, (HttpStatusCode code) =>
            {
                using (var contextAfter = new MyEventsContext())
                {
                    var actual = contextAfter.RoomPoints.Where(q => q.EventDefinitionId == eventDefinition.EventDefinitionId && q.RoomNumber == roomNumber).Count();
                    TestHelper.ValidateResult(0, actual, manualResetEvent, ref exceptionResult);
                }
            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
Esempio n. 12
0
        public void DeleteComment_Integration_CallWebAPI_Deleted_NotFail_Test()
        {
            int expected = 0;
            int sessionId = 0;
            int organizerId = 0;
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            using (var context = new MyEventsContext())
            {
                sessionId = context.Comments.First().SessionId;
                expected = context.Comments.Count(q => q.SessionId == sessionId) - 1;
                organizerId = context.Sessions.Include("EventDefinition")
                    .FirstOrDefault(q => q.SessionId == sessionId).EventDefinition.OrganizerId;
            }

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();
            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(organizerId));
            IAsyncResult ar = service.CommentService.GetAllCommentsAsync(sessionId, (IList<Client.Comment> comments) =>
            {
                IAsyncResult arUpdate = service.CommentService.DeleteCommentAsync(comments.First().CommentId, (HttpStatusCode statusCode) =>
                {
                    using (var context = new MyEventsContext())
                    {
                        int actual = context.Comments.Count(q => q.SessionId == sessionId);
                        TestHelper.ValidateResult(expected, actual, manualResetEvent, ref exceptionResult);
                    }
                });

            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
Esempio n. 13
0
 /// <summary>
 ///  <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="materialId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns></returns>
 public Material Get(int materialId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.Materials.Single(q => q.MaterialId == materialId));
     }
 }
Esempio n. 14
0
 /// <summary>
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="commentId"><see cref="MyEvents.Data.ICommentRepository"/></param>
 /// <returns></returns>
 public Comment Get(int commentId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.Comments.Single(q => q.CommentId == commentId));
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public IList <Session> GetAllWithUserInfo(int registeredUserId, int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.Sessions.Include("SessionRegisteredUsers")
                .Where(q => q.EventDefinitionId == eventDefinitionId)
                .ToList()
                .Select(q => new Session()
         {
             SessionId = q.SessionId,
             Title = q.Title,
             Description = q.Description,
             Speaker = q.Speaker,
             Biography = q.Biography,
             StartTime = q.StartTime,
             Duration = q.Duration,
             RoomNumber = q.RoomNumber,
             AttendeesCount = q.SessionRegisteredUsers.Count(),
             TwitterAccount = q.TwitterAccount,
             TimeZoneOffset = q.TimeZoneOffset,
             EventDefinitionId = q.EventDefinitionId,
             IsFavorite = q.SessionRegisteredUsers.Any(sr => sr.RegisteredUserId == registeredUserId),
             UserScore = q.SessionRegisteredUsers.Any(sr => sr.RegisteredUserId == registeredUserId) ?
                         q.SessionRegisteredUsers.First(sr => sr.RegisteredUserId == registeredUserId).Score : 0,
             Score = q.SessionRegisteredUsers.Any(sr => sr.Rated) ?
                     q.SessionRegisteredUsers.Where(sr => sr.Rated).Average(sr => sr.Score) : 0
         }).ToList());
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public byte[] GetEventLogo(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.EventDefinitions.Where(e => e.EventDefinitionId == eventDefinitionId).Select(e => e.Logo).FirstOrDefault());
     }
 }
Esempio n. 17
0
 /// <summary>
 ///  <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="materialId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns></returns>
 public Material Get(int materialId)
 {
     using (var context = new MyEventsContext())
     {
         return context.Materials.Single(q => q.MaterialId == materialId);
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public int GetCountByOrganizerId(int organizerId, string filter)
 {
     using (var context = new MyEventsContext())
     {
         return(context.EventDefinitions
                .Count(q => q.OrganizerId == organizerId && (String.IsNullOrEmpty(filter) || q.Name.Contains(filter))));
     }
 }
Esempio n. 19
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="material"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IMaterialRepository"/></returns>
 public int Add(Material material)
 {
     using (var context = new MyEventsContext())
     {
         context.Materials.Add(material);
         context.SaveChanges();
         return(material.MaterialId);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="material"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IMaterialRepository"/></returns>
 public int Add(Material material)
 {
     using (var context = new MyEventsContext())
     {
         context.Materials.Add(material);
         context.SaveChanges();
         return material.MaterialId;
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinition"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public int Add(EventDefinition eventDefinition)
 {
     using (var context = new MyEventsContext())
     {
         CheckAndFixTwitterAccount(eventDefinition);
         context.EventDefinitions.Add(eventDefinition);
         context.SaveChanges();
         return(eventDefinition.EventDefinitionId);
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public byte[] GetRoomImage(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.EventDefinitions
                .Where(e => e.EventDefinitionId == eventDefinitionId)
                .Single()
                .MapImage);
     }
 }
Esempio n. 23
0
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="session"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public int Add(Session session)
 {
     using (var context = new MyEventsContext())
     {
         CheckAndFixTwitterAccount(session);
         context.Sessions.Add(session);
         context.SaveChanges();
         return session.SessionId;
     }
 }
Esempio n. 24
0
 /// <summary>
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="comment"><see cref="MyEvents.Data.ICommentRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ICommentRepository"/></returns>
 public int Add(Comment comment)
 {
     using (var context = new MyEventsContext())
     {
         comment.AddedDateTime = DateTime.UtcNow;
         context.Comments.Add(comment);
         context.SaveChanges();
         return comment.CommentId;
     }
 }
Esempio n. 25
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IRegisteredUserRepository"/></returns>
 public IList <RegisteredUser> GetAllByEventId(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.RegisteredUsers
                .Where(q => q.AttendeeEventDefinitions.Any(e => e.EventDefinitionId == eventDefinitionId))
                .OrderBy(q => q.Name)
                .ToList());
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinition"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public int Add(EventDefinition eventDefinition)
 {
     using (var context = new MyEventsContext())
     {
         CheckAndFixTwitterAccount(eventDefinition);
         context.EventDefinitions.Add(eventDefinition);
         context.SaveChanges();
         return eventDefinition.EventDefinitionId;
     }
 }
Esempio n. 27
0
 /// <summary>
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="comment"><see cref="MyEvents.Data.ICommentRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ICommentRepository"/></returns>
 public int Add(Comment comment)
 {
     using (var context = new MyEventsContext())
     {
         comment.AddedDateTime = DateTime.UtcNow;
         context.Comments.Add(comment);
         context.SaveChanges();
         return(comment.CommentId);
     }
 }
Esempio n. 28
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="sessionId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IRegisteredUserRepository"/></returns>
 public IList <RegisteredUser> GetAllBySessionId(int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.RegisteredUsers.Include("SessionRegisteredUsers")
                .Where(q => q.SessionRegisteredUsers.Any(s => s.SessionId == sessionId))
                .OrderBy(q => q.Name)
                .ToList());
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="session"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public int Add(Session session)
 {
     using (var context = new MyEventsContext())
     {
         CheckAndFixTwitterAccount(session);
         context.Sessions.Add(session);
         context.SaveChanges();
         return(session.SessionId);
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 public void Delete(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         var eventDefinition = context.EventDefinitions.FirstOrDefault(q => q.EventDefinitionId == eventDefinitionId);
         if (eventDefinition != null)
         {
             context.EventDefinitions.Remove(eventDefinition);
             context.SaveChanges();
         }
     }
 }
Esempio n. 31
0
 /// <summary>
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="commentId"><see cref="MyEvents.Data.ICommentRepository"/></param>
 public void Delete(int commentId)
 {
     using (var context = new MyEventsContext())
     {
         var comment = context.Comments.FirstOrDefault(q => q.CommentId == commentId);
         if (comment != null)
         {
             context.Comments.Remove(comment);
             context.SaveChanges();
         }
     }
 }
Esempio n. 32
0
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="sessionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 public void Delete(int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         var session = context.Sessions.FirstOrDefault(q => q.SessionId == sessionId);
         if (session != null)
         {
             context.Sessions.Remove(session);
             context.SaveChanges();
         }
     }
 }
Esempio n. 33
0
 /// <summary>
 /// Get if user is already registered
 /// </summary>
 /// <param name="eventDefinitionId"></param>
 /// <param name="registeredUserId"></param>
 /// <returns></returns>
 public bool GetIfUserIsRegistered(int eventDefinitionId, int registeredUserId)
 {
     using (var context = new MyEventsContext())
     {
         var registeredUser = context.RegisteredUsers.Include("AttendeeEventDefinitions").FirstOrDefault(r => r.RegisteredUserId == registeredUserId);
         if (registeredUser != null)
         {
             return(registeredUser.AttendeeEventDefinitions.Select(e => e.EventDefinitionId).Contains(eventDefinitionId));
         }
     }
     return(false);
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 public void Delete(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         var eventDefinition = context.EventDefinitions.FirstOrDefault(q => q.EventDefinitionId == eventDefinitionId);
         if (eventDefinition != null)
         {
             context.EventDefinitions.Remove(eventDefinition);
             context.SaveChanges();
         }
     }
 }
Esempio n. 35
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="materialId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 public void Delete(int materialId)
 {
     using (var context = new MyEventsContext())
     {
         var material = context.Materials.FirstOrDefault(q => q.MaterialId == materialId);
         if (material != null)
         {
             context.Materials.Remove(material);
             context.SaveChanges();
         }
     }
 }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
        /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
        public IList <RoomPoint> GetAllRoomPoints(int eventDefinitionId)
        {
            using (var context = new MyEventsContext())
            {
                var roomPoints = context.RoomPoints
                                 .Where(e => e.EventDefinitionId == eventDefinitionId)
                                 .OrderBy(e => e.RoomNumber)
                                 .ToList();

                return(roomPoints);
            }
        }
Esempio n. 37
0
 /// <summary>
 /// <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="materialId"><see cref="MyEvents.Data.IMaterialRepository"/></param>
 public void Delete(int materialId)
 {
     using (var context = new MyEventsContext())
     {
         var material = context.Materials.FirstOrDefault(q => q.MaterialId == materialId);
         if (material != null)
         {
             context.Materials.Remove(material);
             context.SaveChanges();
         }
     }
 }
Esempio n. 38
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUserId"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="sessionId"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 public void DeleteRegisteredUserFromSession(int registeredUserId, int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         var sessionRegisteredUser = context.SessionRegisteredUsers.FirstOrDefault(q => q.SessionId == sessionId && q.RegisteredUserId == registeredUserId);
         if (sessionRegisteredUser != null)
         {
             context.SessionRegisteredUsers.Remove(sessionRegisteredUser);
             context.SaveChanges();
         }
     }
 }
Esempio n. 39
0
 /// <summary>
 /// <see cref="MyEvents.Data.ICommentRepository"/>
 /// </summary>
 /// <param name="commentId"><see cref="MyEvents.Data.ICommentRepository"/></param>
 public void Delete(int commentId)
 {
     using (var context = new MyEventsContext())
     {
         var comment = context.Comments.FirstOrDefault(q => q.CommentId == commentId);
         if (comment != null)
         {
             context.Comments.Remove(comment);
             context.SaveChanges();
         }
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="sessionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 public void Delete(int sessionId)
 {
     using (var context = new MyEventsContext())
     {
         var session = context.Sessions.FirstOrDefault(q => q.SessionId == sessionId);
         if (session != null)
         {
             context.Sessions.Remove(session);
             context.SaveChanges();
         }
     }
 }
        public void DeleteEventDefinition_CallWebAPI_EventDeleted_NotFail_Test()
        {
            EventDefinition eventDef;
            int organizerId = 0;
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            // Get values to test
            using (var context = new MyEventsContext())
            {
                organizerId = context.RegisteredUsers.First().RegisteredUserId;

                // Create event to delete
                eventDef = new EventDefinition();
                eventDef.OrganizerId = organizerId;
                eventDef.Name = Guid.NewGuid().ToString();
                eventDef.Description = Guid.NewGuid().ToString();
                eventDef.Address = Guid.NewGuid().ToString();
                eventDef.City = Guid.NewGuid().ToString();
                eventDef.Tags = Guid.NewGuid().ToString();
                eventDef.TwitterAccount = Guid.NewGuid().ToString();
                eventDef.RoomNumber = 1;
                eventDef.Date = System.DateTime.Now;
                eventDef.StartTime = System.DateTime.Now;
                eventDef.EndTime = System.DateTime.Now.AddDays(1);
                eventDef.TimeZoneOffset = 2;
                eventDef.Likes = 0;
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                eventDef.Logo = encoding.GetBytes("sample");
                context.EventDefinitions.Add(eventDef);
                context.SaveChanges();
            }

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();

            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(eventDef.OrganizerId));
            IAsyncResult ar = service.EventDefinitionService.GetEventDefinitionByIdAsync(eventDef.EventDefinitionId, (Client.EventDefinition getEvent) =>
            {
                IAsyncResult arUpdate = service.EventDefinitionService.DeleteEventDefinitionAsync(getEvent.EventDefinitionId, (HttpStatusCode statusCode) =>
                {
                    using (var context = new MyEventsContext())
                    {
                        var actual = context.EventDefinitions.FirstOrDefault(q => q.EventDefinitionId == eventDef.EventDefinitionId);
                        TestHelper.ValidateResult(null, actual, manualResetEvent, ref exceptionResult);
                    }
                });

            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
        /// <param name="roomNumber"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void DeleteRoomPoints(int eventDefinitionId, int roomNumber)
        {
            using (var context = new MyEventsContext())
            {
                var roomPoints = context.RoomPoints
                    .Where(q => q.EventDefinitionId == eventDefinitionId && q.RoomNumber == roomNumber)
                    .ToList();
                foreach (var roomPoint in roomPoints)
                    context.RoomPoints.Remove(roomPoint);

                context.SaveChanges();
            }
        }
Esempio n. 43
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IRegisteredUserRepository"/></returns>
 public IList <Session> GetSessions(int eventDefinitionId, int registeredUserId)
 {
     using (var context = new MyEventsContext())
     {
         return(context.Sessions.Include("SessionRegisteredUsers").Include("Comments")
                .Where(q =>
                       q.EventDefinitionId == eventDefinitionId
                       &&
                       q.SessionRegisteredUsers.Any(s => s.RegisteredUserId == registeredUserId))
                .OrderBy(q => q.StartTime)
                .ToList());
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="sessionId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="score"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 public void AddRegisteredUserScore(int registeredUserId, int sessionId, double score)
 {
     using (var context = new MyEventsContext())
     {
         var sessionRegisteredUser = context.SessionRegisteredUsers.FirstOrDefault(q => q.RegisteredUserId == registeredUserId && q.SessionId == sessionId);
         if (sessionRegisteredUser != null)
         {
             sessionRegisteredUser.Rated = true;
             sessionRegisteredUser.Score = score;
             context.SaveChanges();
         }
     }
 }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="eventDefinition"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void UpdateRoomImage(EventDefinition eventDefinition)
        {
            using (var context = new MyEventsContext())
            {
                var eventDefinitionToUpdate = context.EventDefinitions
                                              .FirstOrDefault(q => q.EventDefinitionId == eventDefinition.EventDefinitionId);

                eventDefinitionToUpdate.EventDefinitionId = eventDefinition.EventDefinitionId;
                eventDefinitionToUpdate.MapImage          = eventDefinition.MapImage;

                context.SaveChanges();
            }
        }
Esempio n. 46
0
 /// <summary>
 /// <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUserId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="sessionId"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="score"><see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 public void AddRegisteredUserScore(int registeredUserId, int sessionId, double score)
 {
     using (var context = new MyEventsContext())
     {
         var sessionRegisteredUser = context.SessionRegisteredUsers.FirstOrDefault(q => q.RegisteredUserId == registeredUserId && q.SessionId == sessionId);
         if (sessionRegisteredUser != null)
         {
             sessionRegisteredUser.Rated = true;
             sessionRegisteredUser.Score = score;
             context.SaveChanges();
         }
     }
 }
Esempio n. 47
0
 /// <summary>
 ///  <see cref="MyEvents.Data.IMaterialRepository"/>
 /// </summary>
 /// <param name="materialId"> <see cref="MyEvents.Data.IMaterialRepository"/></param>
 /// <returns> <see cref="MyEvents.Data.IMaterialRepository"/></returns>
 public int GetOrganizerId(int materialId)
 {
     int id = 0;
     using (var context = new MyEventsContext())
     {
         var material = context.Materials.Include("Session.EventDefinition")
             .FirstOrDefault(q => q.MaterialId == materialId);
         if (material != null)
         {
             id = material.Session.EventDefinition.OrganizerId;
         }
     }
     return id;
 }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="roomPoints"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void AddRoomPoints(IEnumerable <RoomPoint> roomPoints)
        {
            using (var context = new MyEventsContext())
            {
                DeleteRoomPoints(roomPoints.First().EventDefinitionId, roomPoints.First().RoomNumber);

                foreach (var roomPoint in roomPoints)
                {
                    context.RoomPoints.Add(roomPoint);
                }

                context.SaveChanges();
            }
        }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="roomPoints"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void AddRoomPoints(IEnumerable<RoomPoint> roomPoints)
        {
            using (var context = new MyEventsContext())
            {
                DeleteRoomPoints(roomPoints.First().EventDefinitionId, roomPoints.First().RoomNumber);

                foreach (var roomPoint in roomPoints)
                {
                    context.RoomPoints.Add(roomPoint);
                }

                context.SaveChanges();
            }
        }
Esempio n. 50
0
        /// <summary>
        ///  <see cref="MyEvents.Data.IMaterialRepository"/>
        /// </summary>
        /// <param name="materialId"> <see cref="MyEvents.Data.IMaterialRepository"/></param>
        /// <returns> <see cref="MyEvents.Data.IMaterialRepository"/></returns>
        public int GetOrganizerId(int materialId)
        {
            int id = 0;

            using (var context = new MyEventsContext())
            {
                var material = context.Materials.Include("Session.EventDefinition")
                               .FirstOrDefault(q => q.MaterialId == materialId);
                if (material != null)
                {
                    id = material.Session.EventDefinition.OrganizerId;
                }
            }
            return(id);
        }
Esempio n. 51
0
        /// <summary>
        ///  <see cref="MyEvents.Data.ICommentRepository"/>
        /// </summary>
        /// <param name="commentId"> <see cref="MyEvents.Data.ICommentRepository"/></param>
        /// <returns> <see cref="MyEvents.Data.ICommentRepository"/></returns>
        public int GetOrganizerId(int commentId)
        {
            int id = 0;

            using (var context = new MyEventsContext())
            {
                var comment = context.Comments.Include("Session.EventDefinition")
                              .FirstOrDefault(q => q.CommentId == commentId);
                if (comment != null)
                {
                    id = comment.Session.EventDefinition.OrganizerId;
                }
            }
            return(id);
        }
 /// <summary>
 ///  <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUser"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 public int Add(RegisteredUser registeredUser)
 {
     using (var context = new MyEventsContext())
     {
         var user = Get(registeredUser.FacebookId);
         if (user == null)
         {
             context.RegisteredUsers.Add(registeredUser);
             context.SaveChanges();
             return registeredUser.RegisteredUserId;
         }
         else
         {
             return user.RegisteredUserId;
         }
     }
 }
 /// <summary>
 ///  <see cref="MyEvents.Data.IRegisteredUserRepository"/>
 /// </summary>
 /// <param name="registeredUserId"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 /// <param name="eventDefinitionId"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param>
 public void AddRegisteredUserToEvent(int registeredUserId, int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         var eventDefinition = context.EventDefinitions.Include("RegisteredUsers").FirstOrDefault(q => q.EventDefinitionId == eventDefinitionId);
         if (eventDefinition != null)
         {
             if (!eventDefinition.RegisteredUsers.Any(s => s.RegisteredUserId == registeredUserId))
             {
                 var registeredUser = context.RegisteredUsers.FirstOrDefault(q => q.RegisteredUserId == registeredUserId);
                 if (registeredUser != null)
                 {
                     eventDefinition.RegisteredUsers.Add(registeredUser);
                     context.SaveChanges();
                 }
             }
         }
     }
 }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="organizerId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public IList<Tag> GetTopTags(int organizerId)
 {
     using (var context = new MyEventsContext())
     {
         return context.EventDefinitions
             .Where(e => e.OrganizerId == organizerId)
             .ToList()
             .SelectMany(e => e.Tags.Split(','))
             .GroupBy(e => e.Trim())
             .Select(g => new Tag() { Name = g.Key, Value = g.Count() })
             .OrderByDescending(e => e.Value)
             .Take(5)
             .ToList();
     }
 }
        /// <summary>
        /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
        /// </summary>
        /// <param name="organizerId"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
        /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
        public IList<Speaker> GetTopSpeakers(int organizerId)
        {
            using (var context = new MyEventsContext())
            {
                var result =  context.Sessions
                    .Include("EventDefinition")
                    .Include("SessionRegisteredUsers")
                    .Where(s => s.EventDefinition.OrganizerId == organizerId)
                    .Select(ru => new Speaker()
                    {
                        Name = ru.Speaker,
                        Score =
                            ru.SessionRegisteredUsers.Any(sru => sru.Rated)
                            ? ru.SessionRegisteredUsers.Where(sru => sru.Rated).Average(sru => sru.Score) : 0
                    })
                    .GroupBy(s => s.Name)
                    .Select(g => new Speaker() { Name = g.Key, Score = g.Average(s => s.Score) })
                    .OrderByDescending(ru => ru.Score)
                    .Take(5)
                    .ToList();

                return result;

            }
        }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="eventDefinition"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void UpdateRoomImage(EventDefinition eventDefinition)
        {
            using (var context = new MyEventsContext())
            {
                var eventDefinitionToUpdate = context.EventDefinitions
                    .FirstOrDefault(q => q.EventDefinitionId == eventDefinition.EventDefinitionId);

                eventDefinitionToUpdate.EventDefinitionId = eventDefinition.EventDefinitionId;
                eventDefinitionToUpdate.MapImage = eventDefinition.MapImage;

                context.SaveChanges();

            }
        }
        /// <summary>
        /// After update eventdefinition we have to clean the room number of the sessions to be sure that all room numbers exist
        /// </summary>
        /// <param name="eventDefinitionId">eventDefinitionId</param>
        /// <param name="roomNumber">Actual room number</param>
        private void CleanRooms(int eventDefinitionId, int roomNumber)
        {
            using (var context = new MyEventsContext())
            {
                // Clean Sessions
                var sessions = context.Sessions
                    .Where(q => q.EventDefinitionId == eventDefinitionId && q.RoomNumber > roomNumber).ToList();
                foreach (var session in sessions)
                    session.RoomNumber = 0;

                // Delete room points of delete rooms
                var roomPoints = context.RoomPoints.Where(q => q.EventDefinitionId == eventDefinitionId && q.RoomNumber > roomNumber).ToList();
                foreach (var roomPoint in roomPoints)
                    context.RoomPoints.Remove(roomPoint);

                context.SaveChanges();
            }
        }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="sessionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
        /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
        public IList<RoomPoint> GetRoomPoints(int sessionId)
        {
            IList<RoomPoint> roomPoints = new List<RoomPoint>();
            using (var context = new MyEventsContext())
            {
                var session = context.Sessions.FirstOrDefault(s => s.SessionId == sessionId);
                if (session != null && session.RoomNumber > 0)
                {
                    roomPoints = context.RoomPoints
                        .Where(e => e.EventDefinitionId == session.EventDefinitionId && e.RoomNumber == session.RoomNumber)
                        .OrderBy(e => e.RoomNumber)
                        .ToList();
                }

                return roomPoints;
            }
        }
 /// <summary>
 /// <see cref="MyEvents.Data.ISessionRepository"/>
 /// </summary>
 /// <param name="eventDefinitionId"><see cref="MyEvents.Data.ISessionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.ISessionRepository"/></returns>
 public byte[] GetRoomImage(int eventDefinitionId)
 {
     using (var context = new MyEventsContext())
     {
         return context.EventDefinitions
             .Where(e => e.EventDefinitionId == eventDefinitionId)
             .Single()
             .MapImage;
     }
 }
        /// <summary>
        /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
        /// </summary>
        /// <param name="eventDefinition"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
        public void Update(EventDefinition eventDefinition)
        {
            using (var context = new MyEventsContext())
            {
                var eventDefinitionToUpdate = context.EventDefinitions
                    .FirstOrDefault(q => q.EventDefinitionId == eventDefinition.EventDefinitionId);

                eventDefinitionToUpdate.EventDefinitionId = eventDefinition.EventDefinitionId;
                eventDefinitionToUpdate.OrganizerId = eventDefinition.OrganizerId;
                eventDefinitionToUpdate.Name = eventDefinition.Name;
                eventDefinitionToUpdate.Description = eventDefinition.Description;
                eventDefinitionToUpdate.Address = eventDefinition.Address;
                eventDefinitionToUpdate.ZipCode = eventDefinition.ZipCode;
                eventDefinitionToUpdate.City = eventDefinition.City;
                eventDefinitionToUpdate.Tags = eventDefinition.Tags;
                eventDefinitionToUpdate.TwitterAccount = eventDefinition.TwitterAccount;
                eventDefinitionToUpdate.TimeZoneOffset = eventDefinition.TimeZoneOffset;
                eventDefinitionToUpdate.RoomNumber = eventDefinition.RoomNumber;
                eventDefinitionToUpdate.Date = eventDefinition.Date;

                // Be sure that the starttime and endtime is in the same day of the event
                eventDefinitionToUpdate.StartTime
                    = new DateTime(eventDefinition.Date.Year, eventDefinition.Date.Month, eventDefinition.Date.Day, eventDefinition.StartTime.Hour, eventDefinition.StartTime.Minute, 0);

                eventDefinitionToUpdate.EndTime
                    = new DateTime(eventDefinition.Date.Year, eventDefinition.Date.Month, eventDefinition.Date.Day, eventDefinition.EndTime.Hour, eventDefinition.EndTime.Minute, 0);

                eventDefinitionToUpdate.Likes = eventDefinition.Likes;
                eventDefinitionToUpdate.Logo = eventDefinition.Logo;
                eventDefinitionToUpdate.Latitude = eventDefinition.Latitude;
                eventDefinitionToUpdate.Longitude = eventDefinition.Longitude;

                CheckAndFixTwitterAccount(eventDefinitionToUpdate);
                context.SaveChanges();

                // After update eventdefinition we have to clean the room number of the sessions to be sure that all room numbers exist
                CleanRooms(eventDefinition.EventDefinitionId, eventDefinition.RoomNumber);
            }
        }