public ActionResult UploadSongFile(int SongId, string FieldName, HttpPostedFileBase File) { //lets get the song first var song = _songService.GetById(SongId); if (CanEdit(song) && (FieldName == "SongFile" || FieldName == "SampleFile")) { //ok so user can edit the song. let's see if it's a sample file or product file if (FieldName == "SongFile") { //size check if (File.ContentLength > _mobSocialSettings.SongFileMaximumUploadSize * 1024) { return Json(new { Success = false, Message = "Maximum allowed file size is " + _mobSocialSettings.SongFileMaximumUploadSize + "KB" }); } } else if (FieldName == "SampleFile") { //size check if (File.ContentLength > _mobSocialSettings.SongFileSampleMaximumUploadSize * 1024) { return Json(new { Success = false, Message = "Maximum allowed file size is " + _mobSocialSettings.SongFileSampleMaximumUploadSize + "KB" }); } } //we are here so files are good to download //save the downloaded files var songFile = new Download() { ContentType = File.ContentType, DownloadGuid = Guid.NewGuid(), Filename = Path.GetFileNameWithoutExtension(File.FileName), Extension = Path.GetExtension(File.FileName), IsNew = true, UseDownloadUrl = false, DownloadBinary = File.GetDownloadBits(), DownloadUrl = "" }; _downloadService.InsertDownload(songFile); //now let's find the associated downloadable product and change it's download var product = _productService.GetProductById(song.AssociatedProductId); int oldDownloadId; if (FieldName == "SongFile") { oldDownloadId = product.DownloadId; product.DownloadId = songFile.Id; product.IsDownload = true; } else { oldDownloadId = product.SampleDownloadId; product.SampleDownloadId = songFile.Id; product.HasSampleDownload = true; //set preview url of song song.PreviewUrl = Url.RouteUrl("GetSampleDownload", new { productId = product.Id }); _songService.Update(song); } //save the product now _productService.UpdateProduct(product); //delete the old download to clean up var download = _downloadService.GetDownloadById(oldDownloadId); if(download != null) _downloadService.DeleteDownload(download); //and now that we have the song with us. let's send the preview and product id to the client return Json(new { Success = true, PreviewUrl = song.PreviewUrl, ProductId = product.Id }); } else { return Json(new { Success = false, Message = "Unauthorized" }); } }