public static PlaylistWithUserDTO Map(Playlist playlist, UserDTO user) { var playlistDTO = new PlaylistWithUserDTO() { Playlist = Mapper.Map<Playlist, PlaylistDTO>(playlist), User = user }; return playlistDTO; }
public virtual ActionResult Edit(PlaylistWithUserDTO editInfo) { if (ModelState.IsValid) { var playlist = Repository.Get<Playlist>(editInfo.Playlist.Id); var rslt = IsUserAllowedToEditEntity(playlist); if (rslt != null) return rslt; playlist.Name = editInfo.Playlist.Name; playlist.Description = editInfo.Playlist.Description; playlist.NumOfSongsLimit = editInfo.Playlist.NumOfSongsLimit; playlist.NextPlayDate = editInfo.Playlist.NextPlayDate; playlist.IsActive = editInfo.Playlist.IsActive; playlist.IsSongsLimitDaily = editInfo.Playlist.IsSongsLimitDaily; /* refresh access token for this page if requred */ try { var accessToken = Dror.Common.Utils.Facebook.GetPageAccessToken( FacebookApp, playlist.LocalBusiness.FanPageId, CurrentUser.Id); if (!string.IsNullOrEmpty(accessToken)) { playlist.LocalBusiness.FBFanPageAccessToken = accessToken; } } catch (FacebookApiException e) { var msg = String.Format( "Failed to retrieve fan page {0} token for user {1}.", playlist.LocalBusiness.FanPageId, CurrentUser.Id); Logger.ErrorFormat(msg, e); } Repository.Update(playlist); return RedirectToAction( "Settings", "LocalBusiness", new RouteValueDictionary(new { playlist.LocalBusiness.Id })); } //TODO: Check why userDTO returns null; editInfo.User = BuildUserDTO(null); return View(MVC.Settings.Views.Edit, editInfo); }
public virtual ActionResult Create(long fanPageId) { var lb = Repository.GetUnique<LocalBusiness>( l => l.FanPageId == fanPageId); /* not authenticating user \ demanding him to be owner of * localbusiness since localbusiness may not yet exit, and user * might haven't logged in */ var playlistDTO = new PlaylistDTO { LocalBusinessId = (lb != null) ? lb.Id : -1, FanPageId = fanPageId, IsActive = true, PublishAdminContentToWall = (lb == null) || lb.PublishAdminContentToWall, PublishUserContentToWall = (lb == null) || lb.PublishUserContentToWall, NumOfSongsLimit = 5 //TODO: set this magic string in some config file }; var playlistWithUserDTO = new PlaylistWithUserDTO { Playlist = playlistDTO, User = BuildUserDTO(null) //no playlist created yet }; return View(MVC.Settings.Views.Create, playlistWithUserDTO); }
public virtual ActionResult Create(PlaylistWithUserDTO pdto) { if (CurrentUser == null) { return View(MVC.Shared.Views.Error, new ErrorMessage( App_GlobalResources.Errors.userNotStored)); } if (ModelState.IsValid) { var playlist = PlaylistDTOFactory.ReverseMap(pdto.Playlist); LocalBusiness localBusiness; if (pdto.Playlist.LocalBusinessId <= 0) { /* if current user is not admin of page he cannot add a * localbusiness */ if (!CurrentUserFBInfo.IsAdmin) { return View(MVC.Shared.Views.Error, new ErrorMessage( App_GlobalResources.Errors.accessDenied)); } //first playlist of a fan page must be active //Remark:value doesn't get sent right from UI, as checkbox value is disabled. playlist.IsActive = true; localBusiness = SaveLocalBusiness(pdto.Playlist.FanPageId); localBusiness.AddOwner(CurrentUser); localBusiness.AddPlaylist(playlist, true); } else { localBusiness = Repository.Get<LocalBusiness>( pdto.Playlist.LocalBusinessId); localBusiness.AddPlaylist(playlist); } //user must own localbusiness for him to add a playlist if (!localBusiness.IsOwner(CurrentUser.Id)) { return View(MVC.Shared.Views.Error, new ErrorMessage( App_GlobalResources.Errors.accessDenied)); } /* refresh access token for this page if requred */ try { var accessToken = Dror.Common.Utils.Facebook.GetPageAccessToken( FacebookApp, playlist.LocalBusiness.FanPageId, CurrentUser.Id); if (!string.IsNullOrEmpty(accessToken)) { playlist.LocalBusiness.FBFanPageAccessToken = accessToken; } } catch (FacebookApiException e) { var msg = String.Format( "Failed to retrieve fan page {0} token for user {1}.", localBusiness.FanPageId, CurrentUser.Id); Logger.ErrorFormat(msg, e); } playlist.CreationDate = DateTime.Now; playlist.LastModifiedDate = DateTime.Now; Repository.SaveOrUpdate(localBusiness); Repository.SaveOrUpdate(playlist); ISocialStreamReader fbStreamReader = new FacebookStreamReader( (advancement, status) => Console.WriteLine(status), (id, entire, percentage) => Console.WriteLine(string.Format("{0}/{1}", percentage, entire)), 0, string.Empty, Logger, FacebookApp, Repository); fbStreamReader.Import(localBusiness.Id, HarvestType.TopTen); return RedirectToAction("Settings", "LocalBusiness", new RouteValueDictionary( new { playlist.LocalBusiness.Id })); } //TODO: Check why userDTO returns null; pdto.User = BuildUserDTO(null); return View(MVC.Settings.Views.Create, pdto); }
public virtual ActionResult CanvasCreate(PlaylistWithUserDTO pdto) { if (!ModelState.IsValid) { return BuildFailureResult(-1, "Model is not valid"); } if (Repository.Query<LocalBusiness>().Any(lb => lb.FanPageId == pdto.Playlist.FanPageId)) { return BuildFailureResult(-1, "Localbusiness already exists"); } var playlist = PlaylistDTOFactory.ReverseMap(pdto.Playlist); if (pdto.Playlist.LocalBusinessId <= 0) { //first playlist of a fan page must be active //Remark:value doesn't get sent right from UI, as checkbox value is disabled. playlist.IsActive = true; var localBusiness = SaveLocalBusiness(pdto.Playlist.FanPageId); localBusiness.AddPlaylist(playlist, true); localBusiness.ImportPlaylist = playlist; playlist.CreationDate = DateTime.Now; playlist.LastModifiedDate = DateTime.Now; Repository.SaveOrUpdate(localBusiness); Repository.SaveOrUpdate(playlist); ISocialStreamReader fbStreamReader = new FacebookStreamReader( (advancement, status) => Console.WriteLine(status), (id, entire, percentage) => Console.WriteLine(string.Format("{0}/{1}", percentage, entire)), 0, string.Empty, Logger, FacebookApp, Repository); fbStreamReader.Import(localBusiness.Id, HarvestType.TopTen); } return BuildSuccessResult(0, null); }