Beispiel #1
0
 private void DisplayWelcomeMessage(User user)
 {
     Service service = new Service();
     Event welcomeMessage = new Event();
     welcomeMessage.Active = true;
     welcomeMessage.CreationTime = DateTime.Now;
     welcomeMessage.Description = "Welcome to doStuff, We are a event based social media! "
     + "You can make groups, events with friends! Here on the left is a plus sign which allows you to create a new event."
     + "To create a new group, please select the dropdown menu above! HAVE FUN! :)";
     welcomeMessage.Location = "doStuff();";
     welcomeMessage.Max = 1;
     welcomeMessage.Min = 1;
     welcomeMessage.Minutes = 11;
     welcomeMessage.Name = "Welcome!";
     welcomeMessage.OwnerId = user.UserID;
     welcomeMessage.Photo = "random";
     welcomeMessage.TimeOfEvent = DateTime.Now + new TimeSpan(0, welcomeMessage.Minutes, 0);
     service.CreateEvent(ref welcomeMessage);
     service.AnswerEvent(user.UserID, welcomeMessage.EventID, false);
 }
Beispiel #2
0
 public bool ValidationOfTimeOfEvent(Event thisEvent)
 {
     DateTime time = DateTime.Now;
     TimeSpan minutes = new TimeSpan(0, thisEvent.Minutes, 0);
     time = time.Add(minutes);
     return thisEvent.TimeOfEvent >= time;
 }
Beispiel #3
0
 public EventViewModel CastToViewModel(Event e, bool? attending)
 {
     EventViewModel eventViewModel = new EventViewModel();
     List<CommentViewModel> commentViews = new List<CommentViewModel>();
     eventViewModel.Owner = database.GetUser(e.OwnerId).DisplayName;
     eventViewModel.Event = e;
     eventViewModel.Attending = attending;
     eventViewModel.Attendees = database.GetAttendees(e.EventID);
     List<Comment> comments = database.GetComments(e.EventID);
     foreach (Comment comment in comments)
     {
         commentViews.Add(CastToViewModel(comment));
     }
     eventViewModel.CommentsViewModels = commentViews;
     if (TimeLeft(e, DateTime.Now).TotalSeconds <= 0)
     {
         eventViewModel.State = State.OFF;
         if (!e.Min.HasValue || e.Min <= eventViewModel.Attendees.Count)
         {
             eventViewModel.State = State.ON;
         }
     }
     else
     {
         eventViewModel.State = State.NOTREACHED;
         if (e.Max.HasValue && e.Max == eventViewModel.Attendees.Count)
         {
             eventViewModel.State = State.FULL;
         }
         else if (!e.Min.HasValue || e.Min <= eventViewModel.Attendees.Count)
         {
             eventViewModel.State = State.REACHED;
         }
     }
     eventViewModel.TimeCreated = DateTimeToMillis(e.CreationTime);
     return eventViewModel;
 }
Beispiel #4
0
 public bool CreateEvent(ref Event newEvent)
 {
     if (database.CreateEvent(ref newEvent))
     {
         EventToUserRelation relation = new EventToUserRelation();
         relation.EventId = newEvent.EventID;
         relation.AttendeeId = newEvent.OwnerId;
         relation.Active = true;
         relation.Answer = true;
         if (database.CreateEventToUserRelation(ref relation))
         {
             if (newEvent.GroupId.HasValue)
             {
                 GroupToEventRelation relation2 = new GroupToEventRelation();
                 relation2.EventId = newEvent.EventID;
                 relation2.GroupId = newEvent.GroupId.Value;
                 relation2.Active = true;
                 if (database.CreateGroupToEventRelation(ref relation2))
                 {
                     return true;
                 }
                 throw new Exception("The Event was created but an error occured when creation the GroupToUserRelation");
             }
             return true;
         }
         throw new Exception("The Event was created but an error occured when creation the EventToUserRelation");
     }
     return false;
 }
Beispiel #5
0
        public TimeSpan TimeLeft(Event time, DateTime now)
        {
            TimeSpan check = new TimeSpan(0, 0, 0);
            TimeSpan addMinutes = new TimeSpan(0, 0, time.Minutes, 0, 0);
            DateTime timeOfDecision = time.CreationTime;
            timeOfDecision = timeOfDecision.Add(addMinutes);
            TimeSpan timeToDecision = timeOfDecision.Subtract(now);

            if (timeToDecision <= check)
            {
                return check;
            }
            return timeToDecision;
        }
Beispiel #6
0
        public ActionResult CreateEvent(int groupId, Event newEvent)
        {
            ViewBag.groupId = groupId;
            var service = new Service();
            User user = service.GetUser(User.Identity.Name);

            if (service.IsMemberOfGroup(user.UserID, groupId) == false)
            {
                ModelState.AddModelError("Error", "Either the group doesn't exist or you do not have access to it.");
                return View();
            }
            else if (newEvent.Min.HasValue && newEvent.Max.HasValue && (newEvent.Max.Value < newEvent.Min.Value))
            {
                ModelState.AddModelError("Error", "Min can't be higher than max");
            }
            else if (!service.ValidationOfTimeOfEvent(newEvent))
            {
                ModelState.AddModelError("Time of event", "Date of event is not valid");
            }
            else if (ModelState.IsValid)
            {
                newEvent.OwnerId = user.UserID;
                newEvent.CreationTime = DateTime.Now;
                newEvent.Active = true;
                if (service.CreateEvent(ref newEvent))
                {
                    return RedirectToAction("Index", new { groupId = groupId });
                }
                ModelState.AddModelError("Error", "Something went wrong when trying to add your event to the group, please try again later.");
                return View();
            }

            return View();
        }
Beispiel #7
0
 public ActionResult CreateEvent(Event newEvent)
 {
     var service = new Service();
     if (newEvent.Min.HasValue && newEvent.Max.HasValue && (newEvent.Max.Value < newEvent.Min.Value))
     {
         ModelState.AddModelError("Error", "Min can't be higher than max");
     }
     else if (!service.ValidationOfTimeOfEvent(newEvent))
     {
         ModelState.AddModelError("Time of event", "Date of event is not valid");
     }
     else if (ModelState.IsValid)
     {
         newEvent.Active = true;
         newEvent.CreationTime = DateTime.Now;
         newEvent.OwnerId = service.GetUser(User.Identity.Name).UserID;
         if (service.CreateEvent(ref newEvent))
         {
             return RedirectToAction("Index");
         }
         else
         {
             ModelState.AddModelError("Error", "An error occured when creating your event, please try again later.");
         }
     }
     return View(newEvent);
 }
Beispiel #8
0
        public void ServiceNewTime()
        {
            Event test1 = new Event(true, null, 1, "", "", "", new DateTime(15, 2, 3, 4, 5, 6), new DateTime(15, 2, 3, 4, 5, 6), 10, "", 0, 0, 0);
            DateTime CurrentTime1 = new DateTime(15, 2, 3, 4, 5, 6);
            Assert.AreEqual(new TimeSpan(0, 10, 0), ServiceTest.TimeLeft(test1, CurrentTime1));

            Event test2 = new Event(true, null, 1, "", "", "", new DateTime(15, 2, 3, 4, 5, 6), new DateTime(15, 2, 3, 4, 5, 6), 20, "", 0, 0, 0);
            DateTime CurrentTime2 = new DateTime(15, 2, 3, 4, 5, 7);
            Assert.AreEqual(new TimeSpan(0, 19, 59), ServiceTest.TimeLeft(test2, CurrentTime2));

            Event test3 = new Event(true, null, 1, "", "", "", new DateTime(15, 2, 3, 4, 5, 6), new DateTime(15, 2, 3, 4, 5, 6), 30, "", 0, 0, 0);
            DateTime CurrentTime3 = new DateTime(15, 2, 3, 4, 6, 6);
            Assert.AreEqual(new TimeSpan(0, 29, 0), ServiceTest.TimeLeft(test3, CurrentTime3));

            Event test4 = new Event(true, null, 1, "", "", "", new DateTime(15, 2, 5, 4, 8, 7), new DateTime(15, 2, 3, 4, 5, 6), 40, "", 0, 0, 0);
            DateTime CurrentTime4 = new DateTime(15, 3, 2, 4, 48, 07);
            Assert.AreEqual(new TimeSpan(0, 0, 0), ServiceTest.TimeLeft(test4, CurrentTime4));

            Event test5 = new Event(true, null, 1, "", "", "", new DateTime(15, 2, 3, 4, 22, 6), new DateTime(15, 2, 3, 4, 5, 6), 50, "", 0, 0, 0);
            DateTime CurrentTime5 = new DateTime(15, 2, 3, 4, 49, 6);
            Assert.AreEqual(new TimeSpan(0, 23, 0), ServiceTest.TimeLeft(test5, CurrentTime5));
        }
Beispiel #9
0
        public void Initialize()
        {
            MockDb mock = new MockDb();

            #region Users
            User user1 = new User
            {
                UserID = 1,
                Active = true,
                UserName = "******",
                DisplayName = "xXx$w4gM4$t3r420xXx",
                BirthYear = 9000,
                Gender = Gender.MALE,
                Email = "[email protected]"
            };
            User user2 = new User
            {
                UserID = 2,
                Active = true,
                UserName = "******",
                DisplayName = "Sultumenni500",
                BirthYear = 1337,
                Gender = Gender.MALE,
                Email = "*****@*****.**"
            };
            User user3 = new User
            {
                UserID = 3,
                Active = true,
                UserName = "******",
                DisplayName = "Pulsmeister99",
                BirthYear = 9000,
                Gender = Gender.FEMALE,
                Email = "*****@*****.**"
            };
            mock.UserList.Add(user1);
            mock.UserList.Add(user2);
            mock.UserList.Add(user3);
            #endregion
            #region Groups

            Group group1 = new Group
            {
                GroupID = 1,
                Active = true,
                OwnerId = 1,
                Name = "Team Gulli"
            };
            Group group2 = new Group
            {
                GroupID = 2,
                Active = true,
                OwnerId = 3,
                Name = "Pulsuvagninn"
            };
            mock.Groups.Add(group1);
            mock.Groups.Add(group2);
            #endregion
            #region Events
            Event event1 = new Event
            {
                EventID = 1,
                Active = true,
                GroupId = null,
                OwnerId = 1,
                Name = "Lan",
                Photo = "",
                Description = "Quake 4 lyfe",
                CreationTime = new DateTime(2015, 5, 6, 12, 30, 1),
                TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0),
                Minutes = 60,
                Location = "the internet",
                Min = 0,
                Max = 5,
            };

            Event event2 = new Event
            {
                EventID = 2,
                Active = true,
                GroupId = 2,
                OwnerId = 3,
                Name = "Pulsuparty",
                Photo = "",
                Description = "pulsulíf",
                CreationTime = new DateTime(2015, 5, 6, 12, 30, 1),
                TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0),
                Minutes = 60,
                Location = "bæjarins bestu",
                Min = 0,
                Max = 5,
            };
            mock.Events.Add(event1);
            mock.Events.Add(event2);

            #endregion
            #region Comments
            Comment comment1 = new Comment
            {
                CommentID = 1,
                Active = true,
                OwnerId = 2,
                Content = "FOKK PULSUR, SULTA IS SUPERIOR",
                CreationTime = new DateTime(2015, 5, 6, 12, 35, 1)
            };
            mock.Comments.Add(comment1);

            #endregion
            #region GroupToUserRelations
            GroupToUserRelation groupUser1 = new GroupToUserRelation
            {
                GroupToUserRelationID = 1,
                Active = true,
                GroupId = 1,
                MemberId = 1
            };

            GroupToUserRelation groupUser2 = new GroupToUserRelation
            {
                GroupToUserRelationID = 2,
                Active = true,
                GroupId = 2,
                MemberId = 3
            };

            GroupToUserRelation groupUser3 = new GroupToUserRelation
            {
                GroupToUserRelationID = 3,
                Active = true,
                GroupId = 2,
                MemberId = 2
            };

            GroupToUserRelation groupUser4 = new GroupToUserRelation
            {
                GroupToUserRelationID = 4,
                Active = true,
                GroupId = 1,
                MemberId = 2
            };
            mock.GroupToUserRelations.Add(groupUser1);
            mock.GroupToUserRelations.Add(groupUser2);
            mock.GroupToUserRelations.Add(groupUser3);
            mock.GroupToUserRelations.Add(groupUser4);

            #endregion
            #region GroupsToEventRelations
            GroupToEventRelation groupEvent1 = new GroupToEventRelation
            {
                GroupToEventRelationID = 1,
                Active = true,
                EventId = 2,
                GroupId = 2
            };
            mock.GroupToEventRelations.Add(groupEvent1);

            #endregion
            #region UserToUserRelations

            UserToUserRelation friendship1 = new UserToUserRelation
            {
                UserToUserRelationID = 1,
                Active = true,
                SenderId = 2,
                ReceiverId = 3,
                Answer = true
            };

            UserToUserRelation friendship2 = new UserToUserRelation
            {
                UserToUserRelationID = 2,
                Active = true,
                SenderId = 1,
                ReceiverId = 2,
                Answer = true
            };

            mock.UserToUserRelations.Add(friendship1);
            mock.UserToUserRelations.Add(friendship2);

            #endregion
            #region EventToUserRelations

            EventToUserRelation eventUser1 = new EventToUserRelation
            {
                EventToUserRelationID = 1,
                Active = true,
                EventId = 1,
                AttendeeId = 1,
                Answer = true
            };

            EventToUserRelation eventUser2 = new EventToUserRelation
            {
                EventToUserRelationID = 2,
                Active = true,
                EventId = 1,
                AttendeeId = 2,
                Answer = null
            };

            EventToUserRelation eventUser3 = new EventToUserRelation
            {
                EventToUserRelationID = 3,
                Active = true,
                EventId = 2,
                AttendeeId = 3,
                Answer = true
            };

            EventToUserRelation eventUser4 = new EventToUserRelation
            {
                EventToUserRelationID = 4,
                Active = true,
                EventId = 2,
                AttendeeId = 2,
                Answer = false
            };

            mock.EventToUserRelations.Add(eventUser1);
            mock.EventToUserRelations.Add(eventUser2);
            mock.EventToUserRelations.Add(eventUser3);
            mock.EventToUserRelations.Add(eventUser4);

            #endregion
            #region EventToCommentRelations

            EventToCommentRelation eventComment1 = new EventToCommentRelation
            {
                EventToCommentRelationID = 1,
                EventId = 2,
                CommentId = 1,
                Active = true

            };

            mock.EventToCommentRelations.Add(eventComment1);
            #endregion

            DbTest = new Database(mock);
            ServiceTest = new Service(DbTest);
        }
Beispiel #10
0
 public bool CreateEvent(Event newEvent)
 {
     //TODO
     return false;
 }
Beispiel #11
0
 bool Equal(Event a, Event b)
 {
     if (a == null && b == null)
     {
         return true;
     }
     if (a == null || b == null)
     {
         return false;
     }
     if (a.EventID != b.EventID)
     {
         return false;
     }
     if (a.Active != b.Active)
     {
         return false;
     }
     if (a.CreationTime != b.CreationTime)
     {
         return false;
     }
     if (a.Description != b.Description)
     {
         return false;
     }
     if (a.GroupId != b.GroupId)
     {
         return false;
     }
     if (a.Location != b.Location)
     {
         return false;
     }
     if (a.Max != b.Max)
     {
         return false;
     }
     if (a.Min != b.Min)
     {
         return false;
     }
     if (a.Minutes != b.Minutes)
     {
         return false;
     }
     if (a.Name != b.Name)
     {
         return false;
     }
     if (a.OwnerId != b.OwnerId)
     {
         return false;
     }
     if (a.Photo != b.Photo)
     {
         return false;
     }
     if (a.TimeOfEvent != b.TimeOfEvent)
     {
         return false;
     }
     return true;
 }
Beispiel #12
0
 public bool CreateEvent(ref Event newEvent)
 {
     context.Events.Add(newEvent);
         context.SaveChanges();
         return true;
 }