public ActionResult EditProfilePic(FormCollection collection)
        {
            ApplicationUser currentUser = accountService.getUserByName(User.Identity.Name);

            accountService.editProfilePicture(currentUser, collection["picLink"]);

            List<Status> userStatuses = statusService.getStatusesByUserForEditProfilePic(currentUser);

            foreach (Status s in userStatuses)
            {
                statusService.editStatusProfilePicture(s, currentUser.ProfilePic);
            }

            Status automaticProfileUpdateStatus = new Status();

            automaticProfileUpdateStatus.UserName = currentUser.UserName;
            automaticProfileUpdateStatus.Date = DateTime.Now;
            automaticProfileUpdateStatus.MediaURL = collection["picLink"];
            automaticProfileUpdateStatus.Post = currentUser.UserName + " just got a new profile picture!";
            automaticProfileUpdateStatus.ProfilePic = currentUser.ProfilePic;
            automaticProfileUpdateStatus.UserID = currentUser.Id;
            automaticProfileUpdateStatus.Karma = 0;

            statusService.addStatus(automaticProfileUpdateStatus);

            string url = this.Request.UrlReferrer.AbsoluteUri;
            return Redirect(url);
        }
 public bool addHobbyToStatus(Status s, Hobby toAdd)
 {
     StatusHobbyConnection sConnection = new StatusHobbyConnection();
     sConnection.StatusID = s.ID;
     sConnection.HobbyID = toAdd.ID;
     db.StatusHobbyConnections.Add(sConnection);
     return db.SaveChanges() != 0;
 }
 public List<Hobby> getHobbiesByStatus(Status s)
 {
     var hobbies = (from c in db.StatusHobbyConnections
                    where c.StatusID == s.ID
                    join h in db.Hobbies on c.HobbyID equals h.ID
                    select h).ToList();
     return hobbies;
 }
 public bool editStatus(Status edited)
 {
     Status s = getStatusByID(edited.ID);
     if (s != null)
     {
         s.Date = edited.Date;
         s.Post = edited.Post;
         s.MediaURL = edited.MediaURL;
         return db.SaveChanges() != 0;
     }
     return false;
 }
        public void addSavedStatus(Status s, ApplicationUser a)
        {
            UserSavedStatusConnection connection = new UserSavedStatusConnection();

            connection.StatusID = s.ID;
            connection.UserID = a.Id;

            if (savedConnectionExists(connection))
            {
                return;
            }

            db.UserSavedStatusConnections.Add(connection);
            db.SaveChanges();
        }
        public ActionResult CreateStatus(FormCollection collection, string id, int? groupID)
        {
            ApplicationUser currentUser = accountService.getUserByName(User.Identity.Name);
            List<Hobby> currentUserHobbies = hobbyService.getHobbiesByUser(currentUser);

            Status s = new Status();

            s.Post = collection["statusText"];

            s.Karma = 0;

            if (collection["url"] != null)
            {
                s.MediaURL = collection["url"];
            }

            if (groupID != null)
            {
                int realGroupID = groupID.Value;
                Group g = groupService.getGroupByID(realGroupID);
                s.GroupID = g.ID;
            }

            s.ProfilePic = currentUser.ProfilePic;
            s.Date = DateTime.Now;
            s.UserID = User.Identity.GetUserId();
            s.UserName = User.Identity.Name;
            if (id != null)
            {
                s.PostedToID = id;
            }
            else
            {
                s.PostedToID = collection["PostedToID"];
            }

            statusService.addStatus(s);

            if (groupID == null)
            {
                foreach (Hobby h in currentUserHobbies)
                {
                    if (collection[h.Name] == h.Name)
                    {
                        statusService.addHobbyToStatus(s, h);
                    }
                }
            }
            else
            {
                int realGroupID = groupID.Value;
                Group g = groupService.getGroupByID(realGroupID);
                List<Hobby> currentGroupHobbies = hobbyService.getHobbiesByGroup(g);

                foreach (Hobby h in currentGroupHobbies)
                {
                    if (collection[h.Name] == h.Name)
                    {
                        statusService.addHobbyToStatus(s, h);
                    }
                }
            }

            string url = this.Request.UrlReferrer.AbsoluteUri;
            return Redirect(url);
        }
        public ActionResult EditStatus(FormCollection collection)
        {
            string url = this.Request.UrlReferrer.AbsoluteUri;

            if (collection["cancel"] == "cancel")
            {
                return Redirect(url);
            }

            int? id = Convert.ToInt32(collection["StatusId"]);
            Status currentStatus = statusService.getStatusByID(id);
            Status editedStatus = new Status();
            editedStatus.ID = currentStatus.ID;
            editedStatus.Date = currentStatus.Date;
            editedStatus.Post = null;
            editedStatus.MediaURL = null;

            string statusTextboxId = "statusTextbox" + Convert.ToString(id);
            string picTextboxId = "picTextbox" + Convert.ToString(id);

            if (currentStatus.Post != null)
            {
                editedStatus.Post = collection[statusTextboxId];
            }
            if (currentStatus.MediaURL != null)
            {
                editedStatus.MediaURL = collection[picTextboxId];
            }

            statusService.editStatus(editedStatus);
            return Redirect(url);
        }
        public bool editStatusProfilePicture(Status s, string link)
        {
            s.ProfilePic = link;

            return db.SaveChanges() != 0;
        }
        public bool downvoteStatus(Status s)
        {
            s.Karma--;

            return db.SaveChanges() != 0;
        }
 public bool addStatus(Status s)
 {
     db.Statuses.Add(s);
     return db.SaveChanges() != 0;
 }
        public bool upvoteStatus(Status s)
        {
            s.Karma++;

            return db.SaveChanges() != 0;
        }
 public bool removeStatus(Status toDel)
 {
     db.Statuses.Remove(toDel);
     return db.SaveChanges() != 0;
 }
        public void removeSavedStatus(Status s, ApplicationUser a)
        {
            UserSavedStatusConnection connection = getUserSavedConnectionByStatusAndUser(s, a);

            db.UserSavedStatusConnections.Remove(connection);
            db.SaveChanges();
        }
 public bool removeHobbyFromStatus(Status s, Hobby toDel)
 {
     StatusHobbyConnection sConnection = new StatusHobbyConnection();
     sConnection.StatusID = s.ID;
     sConnection.HobbyID = toDel.ID;
     db.StatusHobbyConnections.Remove(sConnection);
     return db.SaveChanges() != 0;
 }
 public UserSavedStatusConnection getUserSavedConnectionByStatusAndUser(Status s, ApplicationUser a)
 {
     var connection = (from c in db.UserSavedStatusConnections
                      where (c.StatusID == s.ID) && (c.UserID == a.Id)
                      select c).SingleOrDefault();
     return connection;
 }
 public List<Comment> getCommentsByStatus(Status s)
 {
     var comments = (from c in db.Comments
                     where c.StatusID == s.ID
                     orderby c.DateInserted ascending
                     select c).ToList();
     return comments;
 }