Пример #1
0
        public ActionResult Like(int songId)
        {
            object result;
            if (MP3.Utilities.UserUtilities.GetCurrentUser() == null || db.Songs.Find(songId) == null)
                return HttpNotFound();

            UserProfile user = new UserProfile { UserId = MP3.Utilities.UserUtilities.GetCurrentUser().UserId };
            db.UserProfile.Attach(user);
            Songs song = db.Songs.Find(songId);

            if (song.LikedUsers.Where(u => u.UserId == MP3.Utilities.UserUtilities.GetCurrentUser().UserId).Count() == 0)
            {
                song.LikedUsers.Add(user);
            }
            else
            {
                song.LikedUsers.Remove(user);
            }
            db.SaveChanges();

            result = new { type = "SUCCESS" };
            JsonResult json = new JsonResult();
            json.Data = result;
            return json;
        }
Пример #2
0
        public UserInfoModel(UserProfile profile)
        {
            this.Profile = profile;

            UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);

            string userLink = "<a href=\""+ url.Action("Details", "User", new { id = Profile.UserId }) + "\" title=\"Xem thông tin\">" + Profile.UserName + "</a>";
            List<UserActivity> activities = new List<UserActivity>();

            foreach (Playlists playlist in Profile.Playlists)
            {
                activities.Add(new UserActivity()
                {
                    Activity = userLink + " đã tạo playlist " + "<a href=\""+ url.Action("Details", "Playlist", new { id = playlist.Id, title = MP3.Utilities.StringUtilities.NoSpace(playlist.Name) }) + "\" title=\"Nghe playlist\">" + playlist.Name + "</a>",
                    Time = playlist.CreatedTime
                });

                if (playlist.LastUpdate != null)
                {
                    activities.Add(new UserActivity()
                    {
                        Activity = userLink + " đã cập nhật playlist " + "<a href=\"" + url.Action("Details", "Playlist", new { id = playlist.Id, title = MP3.Utilities.StringUtilities.NoSpace(playlist.Name) }) + "\" title=\"Nghe playlist\">" + playlist.Name + "</a>",
                        Time = playlist.CreatedTime
                    });
                }
            }

            foreach (PlaylistComment playlistComment in Profile.CommentedPlaylists)
            {
                activities.Add(new UserActivity()
                {
                    Activity = userLink + " đã bình luận trong playlist " + "<a href=\"" + url.Action("Details", "Playlist", new { id = playlistComment.Playlists.Id, title = MP3.Utilities.StringUtilities.NoSpace(playlistComment.Playlists.Name) }) + "\" title=\"Nghe playlist\">" + playlistComment.Playlists.Name + "</a>: &ldquo;<span>" + playlistComment.Content + "</span>&rdquo;",
                    Time = playlistComment.Playlists.CreatedTime
                });
            }

            foreach (SongComment songComment in Profile.CommentedSongs)
            {
                activities.Add(new UserActivity()
                {
                    Activity = userLink + " đã bình luận bài hát " + "<a href=\"" + url.Action("Details", "Song", new { id = songComment.Song.Id, title = MP3.Utilities.StringUtilities.NoSpace(songComment.Song.Name) }) + "\" title=\"Nghe bài hát này\">" + songComment.Song.Name + "</a>: &ldquo;<span>" + songComment.Content + "</span>&rdquo;",
                    Time = songComment.Song.CreatedTime
                });
            }

            Activities = activities.OrderBy(a => a.Time).ToList<UserActivity>();
        }