Inheritance: mobSocial.Core.Data.BaseEntity, IPermalinkSupported
Example #1
0
 bool CanEdit(Song Song)
 {
     if (Song == null)
         return false;
     return _workContext.CurrentCustomer.Id == Song.PageOwnerId //page owner
         || _workContext.CurrentCustomer.IsAdmin(); //administrator
 }
Example #2
0
        Song SaveRemoteSongToDB(string songJson)
        {
            if (string.IsNullOrEmpty(songJson))
                return null;

            var song = (JObject)JsonConvert.DeserializeObject(songJson);

            var songPage = new Song() {
                PageOwnerId = _workContext.CurrentCustomer.IsAdmin() ? _workContext.CurrentCustomer.Id : 0,
                Description = song["Description"].ToString(),
                Name = song["Name"].ToString(),
                RemoteEntityId = song["RemoteEntityId"].ToString(),
                RemoteSourceName = song["RemoteSourceName"].ToString(),
                PreviewUrl = song["PreviewUrl"].ToString(),
                TrackId = song["TrackId"].ToString(),
                RemoteArtistId = song["ArtistId"].ToString(),
                Published = true
            };

            _songService.Insert(songPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(song["ImageUrl"].ToString()))
            {
                var imageUrl = song["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGET(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                        fileExtension = fileExtension.ToLowerInvariant();

                    var contentType = PictureUtility.GetContentType(fileExtension);

                    var picture = _pictureService.InsertPicture(imageBytes, contentType, songPage.GetSeName(_workContext.WorkingLanguage.Id, true, false));
                    var songPicture = new SongPicture() {
                        EntityId = songPage.Id,
                        DateCreated = DateTime.Now,
                        DateUpdated = DateTime.Now,
                        DisplayOrder = 1,
                        PictureId = picture.Id
                    };
                    _songService.InsertPicture(songPicture);
                }

            }
            return songPage;
        }
Example #3
0
        public ActionResult SaveSong(SongModel model)
        {
            if (!ModelState.IsValid)
                return Json(new { Success = true });

            if (!_workContext.CurrentCustomer.IsRegistered())
                return InvokeHttp404();

            //every song should be mapped to a downloadable product. downloads are added using upload song action from song page
            var product = new Product() {
                Name = model.Name,
                Price = model.Price,
                IsDownload = true,
                UnlimitedDownloads = true,
                ProductType = ProductType.SimpleProduct,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                OrderMaximumQuantity = 1,
                OrderMinimumQuantity = 1,
                DownloadActivationType = DownloadActivationType.WhenOrderIsPaid
            };

            _productService.InsertProduct(product);

            //now that product has been saved, let's create a song
            var song = new Song() {
                ArtistPageId = model.ArtistPageId,
                Description = model.Description,
                AssociatedProductId = product.Id,
                RemoteEntityId = "",
                RemoteArtistId = "",
                RemoteSourceName = "",
                PageOwnerId = _workContext.CurrentCustomer.Id,
                Name = model.Name,
                Published = false
            };
            _songService.Insert(song);

            return Json(
                new {
                    Success = true,
                    RedirectTo = Url.RouteUrl("SongUrl", new { SeName = song.GetSeName(_workContext.WorkingLanguage.Id, true, false) })
                });
        }