Example #1
0
 public static string GetChannelOwner(int userId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         return proxy.GetUser(userId).Username;
     }
 }
Example #2
0
 public static bool HasChannelTracks(int channelId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         return proxy.GetTrackByChannelId(channelId).Length > 0;
     }
 }
Example #3
0
 public static bool IsChannelPlaying(int channelId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         return proxy.IsChannelPlaying(channelId);
     }
 }
Example #4
0
 public static bool CanStartStopChannels()
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         return proxy.CanStartStopChannels();
     }
 }
Example #5
0
 public static int GetCountChannelComments(int channelId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         return proxy.GetCountChannelComments(channelId);
     }
 }
Example #6
0
 /// <summary>
 /// Adds a track to a channel
 /// </summary>
 /// <param name="file"></param>
 /// <param name="channelId"></param>
 /// <param name="trackName"></param>
 /// <param name="artistName"></param>
 /// <returns></returns>
 public ActionResult AddTrack(HttpPostedFileBase file, int channelId, int? userId, string trackName, string artistName)
 {
     if (userId.HasValue)
     {
         try
         {
             // Verify that the user selected a file
             if (file != null && file.ContentLength > 0)
             {
                 Stream stream = file.InputStream;
                 MemoryStream memory = new MemoryStream();
                 stream.CopyTo(memory);
                 Track track = new Track();
                 track.Artist = artistName;
                 track.Name = trackName;
                 using (RentItServiceClient proxy = new RentItServiceClient())
                 {
                     proxy.AddTrack(userId.Value, channelId, memory);
                 }
             }
         }
         catch (Exception)
         {
         }
         return Redirect(Request.UrlReferrer.PathAndQuery);
     }
     return RedirectToAction("Index", "Home");
 }
Example #7
0
 public static int TotalChannels()
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         ChannelSearchArgs searchArgs = proxy.GetDefaultChannelSearchArgs();
         searchArgs.SortOption = searchArgs.SubscriptionsDesc;
         return proxy.CountAllChannelsWithFilter(searchArgs);
     }
 }
Example #8
0
 public static int TotalChannelsWithFilter(AdvancedSearchModel model)
 {
     int count;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         count = proxy.CountAllChannelsWithFilter((ChannelSearchArgs)model);
     }
     return count;
 }
Example #9
0
 public static int GetUpvotes(int trackId)
 {
     int upvotes;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         upvotes = proxy.CountAllUpvotes(trackId);
     }
     return upvotes;
 }
Example #10
0
 public static int GetDownvotes(int trackId)
 {
     int downvotes;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         downvotes = proxy.CountAllDownvotes(trackId);
     }
     return downvotes;
 }
Example #11
0
 public ActionResult AddComment(Comment comment, int? userId, int? channelId)
 {
     if(userId.HasValue && channelId.HasValue)
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         proxy.CreateComment(comment.Content, userId.Value, channelId.Value);
     }
     return Redirect(Request.UrlReferrer.PathAndQuery);
 }
Example #12
0
 public JsonResult Last5TracksJson(int channelId, int userId)
 {
     List<GuiTrack> guiTracks;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         Track[] tracks = proxy.GetRecentlyPlayedTracks(channelId, 5);
         guiTracks = GuiClassConverter.ConvertTracks(tracks);
     }
     return Json(guiTracks, JsonRequestBehavior.AllowGet);
 }
Example #13
0
 public static List<GuiGenre> GetAllAvailableGenres()
 {
     List<GuiGenre> availableGenres;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         Genre[] allGenres = proxy.GetAllGenres();
         availableGenres = GuiClassConverter.ConvertGenres(allGenres);
     }
     return availableGenres;
 }
Example #14
0
 public PartialViewResult Last5Tracks(int channelId, int userId)
 {
     List<GuiTrack> guiTracks;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         Track[] tracks = proxy.GetRecentlyPlayedTracks(channelId, 5);
         guiTracks = GuiClassConverter.ConvertTracks(tracks);
     }
     return PartialView(new Tuple<List<GuiTrack>, int>(guiTracks, userId));
 }
Example #15
0
 public JsonResult IsCurrentPasswordCorrect(string currentPassword, int userId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         if (proxy.IsCorrectPassword(userId, currentPassword))
         {
             return Json(true, JsonRequestBehavior.AllowGet);
         }
         return Json("The current password is wrong.", JsonRequestBehavior.AllowGet);
     }
 }
Example #16
0
 public JsonResult IsUsernameAvailable(string newUsername)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         if (proxy.IsUsernameAvailable(newUsername))
         {
             return Json(true, JsonRequestBehavior.AllowGet);
         }
         return Json("Username is already in use.", JsonRequestBehavior.AllowGet);
     }
 }
Example #17
0
 public JsonResult IsChannelNameAvailable(string name, int id)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         if (proxy.IsChannelNameAvailable(id, name))
         {
             return Json(true, JsonRequestBehavior.AllowGet);
         }
         return Json("The channel name is already in use.", JsonRequestBehavior.AllowGet);
     }
 }
Example #18
0
 public ActionResult AudioPlayer(int channelId, int userId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         proxy.IncrementChannelPlays(channelId);
     }
     Audio audio = new Audio();
     audio.StreamUri = "http://rentit.itu.dk:27000/" + channelId.ToString();
     audio.ChannelId = channelId;
     return View(new Tuple<Audio, int>(audio, userId));
 }
Example #19
0
 public static int GetVote(int userId, int trackId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         Vote vote = proxy.GetVote(userId, trackId);
         if (vote != null)
         {
             return vote.Value;
         }
         return 0;
     }
 }
Example #20
0
 public ActionResult ChangePassword(Account account, int? userId)
 {
     if (userId.HasValue)
     {
         using (RentItServiceClient proxy = new RentItServiceClient())
         {
             proxy.UpdateUser(userId.Value, null, account.NewPassword, null);
         }
         return Redirect(Request.UrlReferrer.PathAndQuery);
     }
     return RedirectToAction("Index", "Home");
 }
Example #21
0
 public static GuiComment ConvertComment(Comment c)
 {
     GuiComment comment = new GuiComment()
     {
         UserId = c.UserId,
         Content = c.Content,
         Date = c.PostTime,
         ChannelId = c.ChannelId
     };
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         comment.UserName = proxy.GetUser(comment.UserId).Username;
     }
     return comment;
 }
Example #22
0
        //
        // GET: /Comment/
        public PartialViewResult CommentListRange(int channelId, int startIndex, int endIndex)
        {
            if (startIndex <= 0)
            {
                startIndex = 0;
                endIndex = 10;
            }

            Comment[] comments;
            using (RentItServiceClient proxy = new RentItServiceClient())
            {
                comments = proxy.GetChannelComments(channelId, startIndex, endIndex);
            }
            List<GuiComment> guiComments = GuiClassConverter.ConvertComments(comments);
            ViewBag.ChannelId = channelId;
            return PartialView("CommentList", new Tuple<List<GuiComment>, int, int>(guiComments, startIndex, endIndex));
        }
Example #23
0
 public JsonResult IsEmailAvailable(string newEmail)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         try
         {
             if (proxy.IsEmailAvailable(newEmail))
             {
                 return Json(true, JsonRequestBehavior.AllowGet);
             }
         }
         catch
         {
             return Json("Email is already in use.", JsonRequestBehavior.AllowGet);
         }
         return Json("Email is already in use.", JsonRequestBehavior.AllowGet);
     }
 }
Example #24
0
 /// <summary>
 /// Method called to determine if a user has subscribed to a given channel
 /// </summary>
 /// <param name="channelId"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static bool IsSubscribed(int channelId, int userId)
 {
     Channel[] channels;
     try
     {
         using (RentItServiceClient proxy = new RentItServiceClient())
         {
             channels = proxy.GetSubscribedChannels(userId);
         }
     }
     catch (Exception)
     {
         return false;
     }
     foreach (Channel c in channels)
     {
         if (c.Id == channelId)
             return true;
     }
     return false;
 }
Example #25
0
 public static GuiChannel ConvertChannel(Channel c)
 {
     GuiChannel chan = new GuiChannel()
     {
         Id = c.Id,
         Description = c.Description,
         Plays = c.Hits != null ? c.Hits.Value : 0,
         Name = c.Name,
         StreamUri = c.StreamUri,
         OwnerId = c.OwnerId,
     };
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         //Get number of subscribers
         chan.Subscribers = proxy.GetSubscriberCount(chan.Id);
         //Get the channels
         chan.Tracks = ConvertTracks(proxy.GetTrackByChannelId(c.Id));
         //Get the genres
         chan.Genres = ConvertGenres(proxy.GetGenresForChannel(c.Id));
     }
     return chan;
 }
Example #26
0
 public ActionResult SelectChannel(int channelId, int? userId)
 {
     if (userId.HasValue)
     {
         using (RentItServiceClient proxy = new RentItServiceClient())
         {
             Channel serviceChan = proxy.GetChannel(channelId);
             GuiChannel chan = GuiClassConverter.ConvertChannel(serviceChan);
             chan.Genres = GuiClassConverter.ConvertGenres(proxy.GetGenresForChannel(channelId));
             if (chan != null)
             {
                 Session["channelId"] = chan.Id;
                 return View(chan);
             }
         }
     }
     return RedirectToAction("Index", "Home");
 }
Example #27
0
        public ActionResult SearchAdv(string channelName, int? minAmountOfSubscribers, int? maxAmountOfSubscribers, int? minAmountOfComments,
                                      int? maxAmountOfComments, int? minAmountOfPlays, int? maxAmountOfPlays, int? minAmountOfVotes,
                                      int? maxAmountOfVotes, string sortingKey, string sortingBy, int startIndex, int endIndex, SelectedGenrePostModel genres)
        {
            Channel[] channels;
            ChannelSearchArgs searchArgs;
            using (RentItServiceClient proxy = new RentItServiceClient())
            {
                searchArgs = proxy.GetDefaultChannelSearchArgs();
                if (channelName != null && !channelName.Equals(""))
                    searchArgs.SearchString = channelName;
                searchArgs.StartIndex = startIndex;
                searchArgs.EndIndex = endIndex;
                //Subscribers
                searchArgs.MinNumberOfSubscriptions = minAmountOfSubscribers != null ? minAmountOfSubscribers.Value : -1;
                searchArgs.MaxNumberOfSubscriptions = maxAmountOfSubscribers != null ? maxAmountOfSubscribers.Value : int.MaxValue;
                //Comments
                searchArgs.MinNumberOfComments = minAmountOfComments != null ? minAmountOfComments.Value : -1;
                searchArgs.MaxNumberOfComments = maxAmountOfComments != null ? maxAmountOfComments.Value : int.MaxValue;
                //Plays
                searchArgs.MinAmountPlayed = minAmountOfPlays != null ? minAmountOfPlays.Value : -1;
                searchArgs.MaxAmountPlayed = maxAmountOfPlays != null ? maxAmountOfPlays.Value : int.MaxValue;
                //Votes
                searchArgs.MinTotalVotes = minAmountOfVotes != null ? minAmountOfVotes.Value : -1;
                searchArgs.MaxTotalVotes = maxAmountOfVotes != null ? maxAmountOfVotes.Value : int.MaxValue;
                //Sorting
                searchArgs.SortOption = sortingKey + " " + sortingBy;

                searchArgs.Genres = genres.ChosenGenres != null ? genres.ChosenGenres.ToArray() : null;

                channels = proxy.GetChannels(searchArgs);
            }
            List<GuiChannel> guiChannels = GuiClassConverter.ConvertChannels(channels);
            Tuple<List<GuiChannel>, AdvancedSearchModel> model = new Tuple<List<GuiChannel>, AdvancedSearchModel>(guiChannels, (AdvancedSearchModel)searchArgs);
            return View("SearchResults", model);
        }
Example #28
0
 public ActionResult StopChannel(int channelId)
 {
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         if (proxy.CanStartStopChannels())
         {
             proxy.StopChannelStream(channelId);
         }
     }
     return Redirect(Request.UrlReferrer.PathAndQuery);
 }
Example #29
0
 public ActionResult SearchResult(string searchArgs, int? userId)
 {
     if (userId.HasValue)
     {
         SelectedGenrePostModel model = new SelectedGenrePostModel();
         model.ChosenGenres = null;
         return SearchAdv(searchArgs, null, null, null, null, null, null, null, null, "nam", "asc", 0, 10, model);
         using (RentItServiceClient proxy = new RentItServiceClient())
         {
             ChannelSearchArgs channelSearchArgs = proxy.GetDefaultChannelSearchArgs();
             channelSearchArgs.SearchString = searchArgs;
             Channel[] channels = proxy.GetChannels(channelSearchArgs);
             List<GuiChannel> guiChannels = GuiClassConverter.ConvertChannels(channels);
             ViewBag.Title = "Search results";
             return View("ChannelList", guiChannels);
         }
     }
     return RedirectToAction("Index", "Home");
 }
Example #30
0
 public PartialViewResult AdvancedSearchWithArgs(AdvancedSearchModel model)
 {
     if (model.StartIndex < 0)
     {
         model.StartIndex = 0;
         model.EndIndex = 10;
     }
     if (model.SearchString == null)
         model.SearchString = "";
     Channel[] channels;
     using (RentItServiceClient proxy = new RentItServiceClient())
     {
         ChannelSearchArgs searchArgs = (ChannelSearchArgs)model;
         channels = proxy.GetChannels(searchArgs);
     }
     Tuple<List<GuiChannel>, AdvancedSearchModel> tuple = new Tuple<List<GuiChannel>, AdvancedSearchModel>(GuiClassConverter.ConvertChannels(channels), model);
     return PartialView("ChannelListForAdvancedSearch", tuple);
 }