public ActionResult Create([Bind(Include = "Name,Description,Categories,InActive,CreatedBy,CreateDate")] Mood mood) { if (ModelState.IsValid) { mood.CreateDate = DateTime.Now; mood.Key = PoordooytifyKey.Generate(); db.Moods.Add(mood); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mood)); }
public ActionResult UploadAudioFile(HttpPostedFileBase audioFile, Song song, string BitRate) { TempData["InstantPlaySongId"] = 0; var songId = 0; try { if (audioFile.ContentLength > 0) { //song.Key = PoordooytifyKey.Generate(); TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; song.Title = textInfo.ToTitleCase(song.Title); song.Artist = textInfo.ToTitleCase(song.Artist); song.PlayCount = 0; db.Songs.Add(song); song.OrigFilename = Path.GetFileName(audioFile.FileName); song.DateAdded = DateTime.Now; song.Key = PoordooytifyKey.Generate(); db.SaveChanges(); songId = song.Id; string _FileName = song.Title + " - " + song.Artist + " [" + song.Id + "]" + Path.GetExtension(audioFile.FileName); string _path = Path.Combine(Server.MapPath("~/TempUpload"), _FileName); audioFile.SaveAs(_path); var fileToUpload = ConvertToOpus(_path, BitRate); if (System.IO.File.Exists(_path)) { System.IO.File.Delete(_path); } var task = Task.Run(() => UploadToDropbox(fileToUpload, song.Id, song.CloudTokenId)); task.Wait(); TempData["InstantPlaySongId"] = song.Id; TempData.Keep("InstantPlaySongId"); } } catch (Exception ex) { TempData["Message"] = "File upload failed. Err: " + ex.Message; db.Entry(song).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Create")); } finally { } return(RedirectToAction("Index")); }