/// <summary> /// Save Song /// </summary> /// <param name="song"></param> /// <returns></returns> public int SaveSong(Song song) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { SongTable tblUser = new SongTable() { SongID = song.SongID, SongName = song.SongName, Artist = song.Artist, Lyrics = song.Lyrics, UserId = song.UserId }; context.SongTables.Add(tblUser); context.SaveChanges(); transaction.Commit(); song.SongID = tblUser.SongID; return(song.SongID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
/// <summary> /// Update Song /// </summary> /// <param name="song"></param> /// <returns></returns> public int UpdateSong(Song song) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { SongTable tblSong = context.SongTables.Where(t => t.SongID == song.SongID).FirstOrDefault(); if (tblSong != null && tblSong.SongID > 0) { tblSong.SongID = song.SongID; tblSong.SongName = song.SongName ?? tblSong.SongName; tblSong.Artist = song.Artist ?? tblSong.Artist; tblSong.Lyrics = song.Lyrics ?? tblSong.Lyrics; tblSong.UserId = song.UserId > 0 ? song.UserId : tblSong.UserId; } context.SaveChanges(); transaction.Commit(); song.SongID = tblSong.SongID; return(song.SongID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
public List <Song> LoadAllSongs(int userId) { List <Song> songs = null; try { using (SMLDBEntities context = new SMLDBEntities()) { IQueryable <SongTable> tblSongs = context.SongTables.Where(s => s.UserId == userId); if (tblSongs != null && tblSongs.Count() > 0) { foreach (SongTable s in tblSongs) { Song song = new Song { SongID = s.SongID, SongName = s.SongName, Artist = s.Artist, Lyrics = s.Lyrics, UserId = s.UserId }; } } } } catch (Exception ex) { throw ex; } return(songs); }
/// <summary> /// Load Song /// </summary> /// <param name="SongId"></param> /// <returns></returns> public Song LoadSong(int SongId) { Song song = new Song(); try { using (SMLDBEntities context = new SMLDBEntities()) { if (SongId > 0) { SongTable tblSong = context.SongTables.Where(t => t.SongID == SongId).FirstOrDefault(); if (tblSong != null) { song.SongID = tblSong.SongID; song.SongName = tblSong.SongName; song.Artist = tblSong.Artist; song.Lyrics = tblSong.Lyrics; song.UserId = tblSong.UserId; } } } } catch (Exception) { return(null); } return(song); }
/// <summary> /// Load All Songs /// </summary> /// <returns></returns> public List <Song> LoadAllSongs() { List <Song> songs = new List <Song>(); try { using (SMLDBEntities context = new SMLDBEntities()) { var tblSongs = context.SongTables; if (tblSongs != null && tblSongs.Count() > 0) { foreach (SongTable s in tblSongs) { Song song = new Song { SongID = s.SongID, SongName = s.SongName, Artist = s.Artist, Lyrics = s.Lyrics, UserId = s.UserId }; songs.Add(song); } } } } catch (Exception ex) { throw ex; } return(songs); }
/// <summary> /// Update Users /// </summary> /// <param name="user"></param> /// <returns></returns> public int UpdateUser(User user) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { UserTable tblUser = context.UserTables.Where(t => t.UserID == user.UserID).FirstOrDefault(); if (tblUser != null && tblUser.UserID > 0) { tblUser.UserID = user.UserID; tblUser.Email = user.Email ?? tblUser.Email; tblUser.Password = user.Password ?? tblUser.Password; tblUser.UserName = user.UserName ?? tblUser.UserName; } context.SaveChanges(); transaction.Commit(); user.UserID = tblUser.UserID; return(user.UserID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
/// <summary> /// Load User /// </summary> /// <param name="UserId"></param> /// <returns></returns> public User LoadUser(int UserId) { User user = new User(); try { using (SMLDBEntities context = new SMLDBEntities()) { if (UserId > 0) { UserTable tblUser = context.UserTables.Where(t => t.UserID == UserId).FirstOrDefault(); if (tblUser != null) { user.UserID = tblUser.UserID; user.UserName = tblUser.UserName; user.Password = tblUser.Password; user.Email = tblUser.Email; } } } } catch (Exception) { return(null); } return(user); }
/// <summary> /// Save Users /// </summary> /// <param name="user"></param> /// <returns></returns> public int SaveUser(User user) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { UserTable tblUser = new UserTable() { UserID = user.UserID, Email = user.Email, Password = user.Password, UserName = user.UserName }; context.UserTables.Add(tblUser); context.SaveChanges(); transaction.Commit(); user.UserID = tblUser.UserID; return(user.UserID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
//delete song public void DeleteSong(int SongId) { using (SMLDBEntities dbContext = new SMLDBEntities()) { var singleRec = dbContext.SongTables.FirstOrDefault(x => x.SongID == SongId);// object your want to delete dbContext.SongTables.Remove(singleRec); dbContext.SaveChanges(); } }
public ActionResult Register(BigViewModel obj) { if (ModelState.IsValid) { SMLDBEntities db = new SMLDBEntities(); db.UserTables.Add(obj.UserTable); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index() { if (Session["UserID"] != null) { return(RedirectToAction("Index", "User")); } else { SMLDBEntities songs = new SMLDBEntities(); BigViewModel bvm = new BigViewModel(); bvm.SongTable = new List <SongTable>(); bvm.SongTable = songs.SongTables.ToList(); return(View(bvm)); } }
public ActionResult Login(BigViewModel objUser) { if (ModelState.IsValid) { using (SMLDBEntities db = new SMLDBEntities()) { var obj = db.UserTables.Where(a => a.UserName.Equals(objUser.UserTable.UserName) && a.Password.Equals(objUser.UserTable.Password)).FirstOrDefault(); if (obj != null) { Session["UserID"] = obj.UserID.ToString(); Session["UserName"] = obj.UserName.ToString(); Session["Email"] = obj.Email.ToString(); return(RedirectToAction("Index", "User")); } } } return(RedirectToAction("Index", "Home")); }
public User UserLogin(User user) { User userDetail = new User(); try { using (SMLDBEntities context = new SMLDBEntities()) { UserTable tblUser = context.UserTables.Where(u => (u.Email == user.Email || u.UserName == user.UserName) && u.Password == user.Password).FirstOrDefault(); if (tblUser != null) { userDetail.UserID = tblUser.UserID; userDetail.UserName = tblUser.UserName; userDetail.Password = tblUser.Password; userDetail.Email = tblUser.Email; } } } catch (Exception) { return(null); } return(userDetail); }