Пример #1
0
 public ActionResult AddMember(int groupId, string username)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User member = service.GetUser(username);
     if (service.IsOwnerOfGroup(user.UserID, groupId) == false)
     {
         TempData["message"] = new Message("Only the owner of a group can add a member to it", MessageType.INFORMATION);
     }
     else if (member == null)
     {
         TempData["message"] = new Message("The username " + username + " could not be found.", MessageType.INFORMATION);
     }
     else if (User.Identity.Name == member.UserName)
     {
         TempData["message"] = new Message("You are already in the group.", MessageType.INFORMATION);
     }
     else if (service.IsMemberOfGroup(member.UserID, groupId))
     {
         TempData["message"] = new Message(username + " is already in the group.", MessageType.INFORMATION);
     }
     else if (service.AddMember(member.UserID, groupId))
     {
         TempData["message"] = new Message(member.UserName + " was added to the group.", MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("An error occured when trying to add " + username + "to the group, please try again later.", MessageType.ERROR);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { member = member, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index", new { groupId = groupId });
 }
Пример #2
0
 public ActionResult AddFriend(string username)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User friend = service.GetUser(username);
     if (friend == null)
     {
         TempData["message"] = new Message("The username " + username + " could not be found.", MessageType.INFORMATION);
     }
     else if (User.Identity.Name == friend.UserName)
     {
         TempData["message"] = new Message("You can't add yourself to your friend list.", MessageType.INFORMATION);
     }
     else if (service.IsFriendsWith(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " is already your friend.", MessageType.INFORMATION);
     }
     else if (service.FriendRequestExists(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " still has a pending friend request", MessageType.INFORMATION);
     }
     else if (service.SendFriendRequest(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " has received your friend request.", MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("Could not process Add Friend request please try again later.", MessageType.ERROR);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index");
 }
Пример #3
0
 public ActionResult AnswerEvent(int groupId, int eventId, bool answer)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     if (service.IsInvitedToEvent(user.UserID, eventId))
     {
         Event theEvent = service.GetEventById(eventId);
         EventViewModel model = service.CastToViewModel(theEvent, null);
         if (model.State == State.FULL)
         {
             TempData["message"] = new Message("This event is already full", MessageType.INFORMATION);
         }
         else if (answer && (model.State == State.OFF || model.State == State.ON))
         {
             TempData["message"] = new Message("This event has expired", MessageType.INFORMATION);
         }
         else if (service.AnswerEvent(user.UserID, eventId, answer))
         {
             if (answer)
             {
                 TempData["message"] = new Message("You are listed as an attendee of " + theEvent.Name, MessageType.SUCCESS);
             }
             else
             {
                 TempData["message"] = new Message("You declined the invitation to " + theEvent.Name, MessageType.SUCCESS);
             }
         }
         else
         {
             TempData["message"] = new Message("An error occured when processing your request, please try again later.", MessageType.ERROR);
         }
     }
     else
     {
         TempData["message"] = new Message("Either the event you are trying to access doesn't exist or you do not have sufficient access to it.", MessageType.INFORMATION);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { id = eventId, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index");
 }
Пример #4
0
 public ActionResult AcceptFriendRequest(int requesterId)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User friend = service.GetUser(requesterId);
     if (service.IsFriendsWith(user.UserID, requesterId))
     {
         TempData["message"] = new Message(friend.DisplayName + " is already your friend", MessageType.INFORMATION);
     }
     else if (service.AnswerFriendRequest(friend.UserID, user.UserID, true))
     {
         TempData["message"] = new Message("You are now friends with " + friend.DisplayName, MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("The friend request you are trying to access no longer exists.", MessageType.INFORMATION);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index");
 }
Пример #5
0
        public ActionResult Comment(int eventId, string content)
        {
            var service = new Service();
            User user = service.GetUser(User.Identity.Name);
            if (String.IsNullOrEmpty(content))
            {

            }
            else if (service.IsInvitedToEvent(user.UserID, eventId))
            {
                Comment myComment = new Comment();
                myComment.Content = content;
                myComment.Active = true;
                myComment.OwnerId = user.UserID;
                myComment.CreationTime = DateTime.Now;
                if (!service.CreateComment(eventId, ref myComment))
                {
                    TempData["Message"] = new Message("An Error occured when processing your event, please try again later", MessageType.ERROR);
                }
            }
            else
            {
                TempData["message"] = new Message("Either the event you are trying to access doesn't exist or you do not have sufficient access to it.", MessageType.INFORMATION);
            }
            if (Request.IsAjaxRequest())
            {
                return Json(new { id = eventId, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
            }
            return RedirectToAction("Index");
        }
Пример #6
0
        public ActionResult RemoveFriend(int friendId)
        {
            var service = new Service();
            User user = service.GetUser(User.Identity.Name);
            User friend = service.GetUser(friendId);
            User parameter = null;

            if (service.IsFriendsWith(user.UserID, friendId))
            {
                TempData["message"] = new Message("You are no longer friends with " + friend.DisplayName, MessageType.SUCCESS);
                if (service.RemoveFriend(user.UserID, friendId))
                {
                    parameter = friend;
                }
            }
            else if (service.FriendRequestExists(user.UserID, friendId))
            {
                if (service.FriendRequestCancel(user.UserID, friendId))
                {
                    parameter = friend;
                }
                TempData["message"] = new Message("Friend request to " + friend.DisplayName + " has been cancelled", MessageType.SUCCESS);
            }
            else
            {
                if (friend != null)
                {
                    TempData["message"] = new Message("You are not friends with " + friend.DisplayName, MessageType.ERROR);
                }
                else
                {
                    TempData["message"] = new Message("User could not be found", MessageType.ERROR);
                }
            }
            if (Request.IsAjaxRequest())
            {
                return Json(new { friend = parameter, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
            }
            return RedirectToAction("Index");
        }
Пример #7
0
        public ActionResult Index()
        {
            var service = new Service();
            SetUserFeedback();
            EventFeedViewModel feed;

            User user = service.GetUser(User.Identity.Name);

            feed = service.GetEventFeed(user.UserID);

            if (Request.IsAjaxRequest())
            {
                return Json(RenderPartialViewToString("EventFeed", feed), JsonRequestBehavior.AllowGet);
            }

            return View("Index", feed);
        }
Пример #8
0
 public ActionResult GetSideBar()
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     if (Request.IsAjaxRequest())
     {
         EventFeedViewModel model = new EventFeedViewModel();
         model.SideBar = service.GetSideBar(user.UserID, null);
         return Json(RenderPartialViewToString("SideBar", model), JsonRequestBehavior.AllowGet);
     }
     return View("Index");
 }
Пример #9
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);
 }
Пример #10
0
 public ActionResult DeclineFriendRequest(int requesterId)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User friend = service.GetUser(requesterId);
     if (service.AnswerFriendRequest(requesterId, user.UserID, false))
     {
         TempData["message"] = new Message("You declined a friend request from " + friend.DisplayName, MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("Could not find that specific friend request, maybe the other user withdrew it.", MessageType.ERROR);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { friend = friend, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index");
 }
Пример #11
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);
 }
Пример #12
0
        public ActionResult CreateEvent(int groupId)
        {
            var service = new Service();
            User user = service.GetUser(User.Identity.Name);

            if (service.IsMemberOfGroup(user.UserID, groupId) == false)
            {
                return RedirectToAction("Index", "User");
            }

            ViewBag.groupId = groupId;
            return View();
        }
Пример #13
0
 public ActionResult RemoveMember(int groupId, int memberId)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User member = null;
     if (memberId == user.UserID)
     {
         TempData["message"] = new Message("You left the group.", MessageType.SUCCESS);
         service.RemoveMember(memberId, groupId);
         return RedirectToAction("Index", "User");
     }
     else if (service.IsOwnerOfGroup(user.UserID, groupId) == false)
     {
         TempData["message"] = new Message("You are not the owner of this group.", MessageType.WARNING);
     }
     else if (service.RemoveMember(memberId, groupId))
     {
         member = service.GetUser(memberId);
         TempData["message"] = new Message(member.DisplayName + " has been removed from the group", MessageType.SUCCESS);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { member = member, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index", "Group", new { groupId = groupId });
 }
Пример #14
0
 public ActionResult Index(int? groupId)
 {
     if (groupId == null)
     {
         return RedirectToAction("Index", "User");
     }
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     if (service.IsMemberOfGroup(user.UserID, groupId.Value))
     {
         GroupFeedViewModel model = service.GetGroupFeed(groupId.Value, user.UserID);
         if (Request.IsAjaxRequest())
         {
             return Json(RenderPartialViewToString("GroupFeed", model), JsonRequestBehavior.AllowGet);
         }
         SetUserFeedback();
         return View(model);
     }
     return RedirectToAction("Index", "User");
 }
Пример #15
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();
        }
Пример #16
0
 public ActionResult GetSideBar(int groupId)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     if (service.IsMemberOfGroup(user.UserID, groupId))
     {
         if (Request.IsAjaxRequest())
         {
             GroupFeedViewModel model = new GroupFeedViewModel();
             model.SideBar = service.GetSideBar(user.UserID, groupId);
             model.Group = service.GetGroupById(groupId);
             return Json(RenderPartialViewToString("SideBar", model), JsonRequestBehavior.AllowGet);
         }
     }
     return Json(null, JsonRequestBehavior.AllowGet);
 }
Пример #17
0
 public ActionResult CreateGroup(string name)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     if (String.IsNullOrEmpty(name))
     {
         TempData["message"] = new Message("Group name can not be empty.", MessageType.ERROR);
         return RedirectToAction("CreateGroup");
     }
     Group group = new Group(true, user.UserID, name, 0);
     if (service.CreateGroup(ref group))
     {
         TempData["message"] = new Message("Your group was created!", MessageType.SUCCESS);
         return RedirectToAction("Index", new { groupId = group.GroupID });
     }
     TempData["message"] = new Message("Your group could not be created, please try again later.", MessageType.ERROR);
     return RedirectToAction("Index");
 }
Пример #18
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);

                    var service = new Service();
                    User register = new User();
                    register.Active = true;
                    register.BirthYear = model.BirthYear;
                    register.DisplayName = model.DisplayName;
                    register.Email = model.Email;
                    register.Gender = model.Gender;
                    register.UserName = model.UserName;
                    service.CreateUser(ref register);

                    DisplayWelcomeMessage(register);
                    return RedirectToAction("Index", "User");
                }
                else
                {
                    ModelState.AddModelError("UserName", "That username is already taken");
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form.
            return View(model);
        }
Пример #19
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);
        }