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); }
public ActionResult UploadPicture(int SongId, IEnumerable <HttpPostedFileBase> file) { //first get song var song = _songService.GetById(SongId); if (!CanEdit(song)) { return(Json(new { Success = false, Message = "Unauthorized" })); } var files = file.ToList(); var imageUrl = ""; var product = _productService.GetProductById(song.AssociatedProductId); if (product == null) { return(Json(new { Success = false, Message = "NoAssociatedProduct" })); } foreach (var fi in files) { Stream stream = null; var fileName = ""; var contentType = ""; if (file == null) { throw new ArgumentException("No file uploaded"); } stream = fi.InputStream; fileName = Path.GetFileName(fi.FileName); contentType = fi.ContentType; var fileBinary = new byte[stream.Length]; stream.Read(fileBinary, 0, fileBinary.Length); var fileExtension = Path.GetExtension(fileName); if (!String.IsNullOrEmpty(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } if (String.IsNullOrEmpty(contentType)) { contentType = PictureUtility.GetContentType(fileExtension); } var picture = _pictureService.InsertPicture(fileBinary, contentType, null); var firstSongPicture = _songService.GetFirstEntityPicture(SongId); if (firstSongPicture == null) { firstSongPicture = new SongPicture() { EntityId = SongId, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, DisplayOrder = 1, PictureId = picture.Id }; _songService.InsertPicture(firstSongPicture); } else { firstSongPicture.EntityId = SongId; firstSongPicture.DateCreated = DateTime.Now; firstSongPicture.DateUpdated = DateTime.Now; firstSongPicture.DisplayOrder = 1; firstSongPicture.PictureId = picture.Id; _songService.UpdatePicture(firstSongPicture); } //add the same picture to product as well product.ProductPictures.Add(new ProductPicture() { PictureId = firstSongPicture.PictureId, ProductId = product.Id }); imageUrl = _pictureService.GetPictureUrl(firstSongPicture.PictureId, 0, true); } return(Json(new { Success = true, Url = imageUrl })); }
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; }
public ActionResult UploadPicture(int SongId, IEnumerable<HttpPostedFileBase> file) { //first get song var song = _songService.GetById(SongId); if (!CanEdit(song)) return Json(new { Success = false, Message = "Unauthorized" }); var files = file.ToList(); var imageUrl = ""; var product = _productService.GetProductById(song.AssociatedProductId); if (product == null) { return Json(new { Success = false, Message = "NoAssociatedProduct" }); } foreach (var fi in files) { Stream stream = null; var fileName = ""; var contentType = ""; if (file == null) throw new ArgumentException("No file uploaded"); stream = fi.InputStream; fileName = Path.GetFileName(fi.FileName); contentType = fi.ContentType; var fileBinary = new byte[stream.Length]; stream.Read(fileBinary, 0, fileBinary.Length); var fileExtension = Path.GetExtension(fileName); if (!String.IsNullOrEmpty(fileExtension)) fileExtension = fileExtension.ToLowerInvariant(); if (String.IsNullOrEmpty(contentType)) { contentType = PictureUtility.GetContentType(fileExtension); } var picture = _pictureService.InsertPicture(fileBinary, contentType, null); var firstSongPicture = _songService.GetFirstEntityPicture(SongId); if (firstSongPicture == null) { firstSongPicture = new SongPicture() { EntityId = SongId, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, DisplayOrder = 1, PictureId = picture.Id }; _songService.InsertPicture(firstSongPicture); } else { firstSongPicture.EntityId = SongId; firstSongPicture.DateCreated = DateTime.Now; firstSongPicture.DateUpdated = DateTime.Now; firstSongPicture.DisplayOrder = 1; firstSongPicture.PictureId = picture.Id; _songService.UpdatePicture(firstSongPicture); } //add the same picture to product as well product.ProductPictures.Add(new ProductPicture() { PictureId = firstSongPicture.PictureId, ProductId = product.Id }); imageUrl = _pictureService.GetPictureUrl(firstSongPicture.PictureId, 0, true); } return Json(new { Success = true, Url = imageUrl }); }
private void OnStateChanged(object sender, RoutedEventArgs e) { SongPicture sp = (SongPicture)(((CheckBox)sender).DataContext); ((EpisodeItem)DataContext).PictureSelected(sp, ((CheckBox)sender).IsChecked); }
private void OnMouseDown(object sender, MouseButtonEventArgs e) { SongPicture sp = (SongPicture)(((Border)sender).DataContext); ((EpisodeItem)DataContext).PictureClicked(sp); }
private void SavePicture(SongPicture sp) { // add to the database using (var transaction = session.BeginTransaction()) { session.Save(sp); transaction.Commit(); } }