public ActionResult AddCommand(string Commandname, string ddlplaylist, string Commandtime) { var listname = db.Playlists.Where(x => x.Title == ddlplaylist).FirstOrDefault(); Playlist1 addcommand = new Playlist1(); addcommand.Command = Commandname; addcommand.Name = ddlplaylist; addcommand.Cmd_Parameter = TimeSpan.Parse(Commandtime); db.Playlists1.Add(addcommand); db.SaveChanges(); db.SaveChanges(); //string UniqueListId = "P" + string.Format("{0:D10}", addcommand.ID); if (addcommand.ID > 0) { addcommand.PID = listname.UID; db.SaveChanges(); } return(RedirectToAction("Home")); }
public ActionResult ImportLogs(HttpPostedFileBase postedFile) { List <Log> ImportLogs = new List <Log>(); string filePath = string.Empty; if (postedFile != null) { string path = Server.MapPath("~/Content/Logfiles/ImportLogs/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(postedFile.FileName); string extension = Path.GetExtension(postedFile.FileName); postedFile.SaveAs(filePath); //Read the contents of CSV file. string csvData = System.IO.File.ReadAllText(filePath); //Execute a loop over the rows. foreach (string row in csvData.Split('\n')) { if (!string.IsNullOrEmpty(row)) { ImportLogs.Add(new Log { //EventTime = Convert.ToDateTime(row.Split(',')[0]), CartId = row.Split(',')[1], Title = row.Split(',')[2], //Duration = TimeSpan.Parse(row.Split(',')[3].ToString()), Playlistname = row.Split(',')[4], }); } } Playlist playlist = new Playlist(); playlist.Title = "Log" + "" + DateTime.Now.ToString("dd/MM/yyyy hh:mm tt"); db.Playlists.Add(playlist); db.SaveChanges(); string UniqueListId = "P" + string.Format("{0:D10}", playlist.ID); if (playlist.ID > 0) { playlist.UID = UniqueListId; db.SaveChanges(); } Playlist1 playlist1 = new Playlist1(); foreach (var item in ImportLogs) { var getaudiodetail = db.Audios.FirstOrDefault(x => x.UID == item.CartId); playlist1.Name = playlist.Title; playlist1.Title = item.Title; playlist1.UID = getaudiodetail.UID; playlist1.Length = getaudiodetail.FileSize; playlist1.PID = playlist.UID; db.Playlists1.Add(playlist1); db.SaveChanges(); //sortorder to display song if (playlist1.ID > 0) { playlist1.OrderSort = playlist1.ID; db.SaveChanges(); } } } return(RedirectToAction("Loghistory")); }
public JsonResult AddPlayList(string listname, string NewSongId, string playlistname) { dynamic showMessageString = string.Empty; int songid = 0; if (!string.IsNullOrEmpty(NewSongId)) { songid = Convert.ToInt32(NewSongId); } try { if (!string.IsNullOrEmpty(listname)) { Playlist AddList = new Playlist(); AddList.Title = listname; db.Playlists.Add(AddList); db.SaveChanges(); string UniqueListId = "P" + string.Format("{0:D10}", AddList.ID); if (AddList.ID > 0) { AddList.UID = UniqueListId; db.SaveChanges(); } var getsong = db.Audios.FirstOrDefault(x => x.ID == songid); // adding song to newly created playlist try { Playlist1 addsong = new Playlist1(); addsong.Name = AddList.Title; addsong.UID = getsong.UID; addsong.Title = getsong.Filename; addsong.Length = getsong.FileSize; db.Playlists1.Add(addsong); db.SaveChanges(); //sortorder to display song if (addsong.ID > 0) { addsong.OrderSort = addsong.ID; db.SaveChanges(); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } else if (!string.IsNullOrEmpty(playlistname)) { var Playlistsong = db.Audios.FirstOrDefault(x => x.ID == songid); var playlistid = Convert.ToInt32(playlistname); var playlistdetail = db.Playlists.FirstOrDefault(x => x.ID == playlistid); // adding song to newly created playlist try { Playlist1 addsong1 = new Playlist1(); addsong1.Name = playlistname; addsong1.PID = playlistdetail.UID; addsong1.UID = Playlistsong.UID; addsong1.Title = Playlistsong.Filename; addsong1.Length = Playlistsong.FileSize; db.Playlists1.Add(addsong1); db.SaveChanges(); //sortorder to display song if (addsong1.ID > 0) { addsong1.OrderSort = addsong1.ID; db.SaveChanges(); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } showMessageString = new { param1 = 200, param2 = "Play list created successfully." }; return(Json(showMessageString, JsonRequestBehavior.AllowGet)); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } showMessageString = new { param1 = 404, param2 = "Error occurred while creating list" }; return(Json(showMessageString, JsonRequestBehavior.AllowGet)); } }