public bool insert(MoodyContext db, [FromBody] Song song) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Song s = new Song { Title = song.Title, Subtitle = song.Subtitle, AlbumId = song.AlbumId, ContributingArtist = song.ContributingArtist, Composer = song.Composer, DateReleased = song.DateReleased, Lyric = song.Lyric, LastModifyAt = DateTime.Now, LastModifyBy = admin.UserId }; db.Song.Add(s); db.SaveChanges(); foreach (var t in song.Tag) { t.SongCode = s.SongCode; } s.Tag = song.Tag; db.SaveChanges(); return(true); }
public bool rating(MoodyContext db, int songID, float score) { bool rated = false; Rating rate = getRated(db, songID); if (rate == null) { Member logged = HttpContext.Session.Get <Member>("MEMBER"); db.Rating.Add(new Rating { UserId = logged.UserId, SongId = songID, Score = score, }); rated = true; } else { rate.Score = score; rated = true; } db.SaveChanges(); Song song = db.Song.Where(s => s.SongCode == songID).FirstOrDefault(); song.Rating = db.Rating.Average(s => s.Score); db.SaveChanges(); return(rated); }
public bool delete(MoodyContext db, [FromBody] Song song) { db.Tag.RemoveRange(db.Tag.Where(tag => tag.SongCode == song.SongCode)); db.Song.Remove(db.Song.Where(a => a.SongCode == song.SongCode).First()); db.SaveChanges(); return(true); }
public Song get(MoodyContext db, int id) { Song song = db.Song.Where(s => s.SongCode == id).FirstOrDefault(); song.ListeningFrequency++; db.SaveChanges(); return(song); }
public bool update(MoodyContext db, [FromBody] Category category) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Category t = db.Category.Where(c => c.TagCode == category.TagCode).First(); t.TagName = category.TagName; t.LastModifyAt = DateTime.Now; t.LastModifyBy = admin.UserId; db.SaveChanges(); return(true); }
public bool insert(MoodyContext db, [FromBody] Category category) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); db.Category.Add(new Category { TagName = category.TagName, LastModifyAt = DateTime.Now, LastModifyBy = admin.UserId }); db.SaveChanges(); return(true); }
public bool update(MoodyContext db, [FromBody] Album album) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Album t = db.Album.Where(a => a.AlbumId == album.AlbumId).First(); t.AlbumName = album.AlbumName; t.Genre = album.Genre; t.DateReleased = album.DateReleased; t.LastModifyBy = admin.UserId; t.LastModifyAt = DateTime.Now; db.SaveChanges(); return(true); }
public bool update(MoodyContext db, [FromBody] Producer producer) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Producer t = db.Producer.Where(a => a.ProducerCode == producer.ProducerCode).First(); t.CompanyName = producer.CompanyName; t.Owner = producer.Owner; t.Address = producer.Address; t.LastModifyBy = admin.UserId; t.LastModifyAt = DateTime.Now; db.SaveChanges(); return(true); }
public bool insert(MoodyContext db, [FromBody] Album album) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); db.Album.Add(new Album { AlbumName = album.AlbumName, Genre = album.Genre, DateReleased = album.DateReleased, LastModifyAt = DateTime.Now, LastModifyBy = admin.UserId }); db.SaveChanges(); return(true); }
public bool update(MoodyContext db, [FromBody] Song song) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Song t = db.Song.Where(a => a.SongCode == song.SongCode).First(); t.Title = song.Title; t.Subtitle = song.Subtitle; t.AlbumId = song.AlbumId; t.ContributingArtist = song.ContributingArtist; t.Composer = song.Composer; t.DateReleased = song.DateReleased; t.Lyric = song.Lyric; t.LastModifyBy = admin.UserId; t.LastModifyAt = DateTime.Now; db.SaveChanges(); db.Tag.RemoveRange(db.Tag.Where(tag => tag.SongCode == song.SongCode)); db.SaveChanges(); foreach (var tag in song.Tag) { db.Tag.Add(tag); } db.SaveChanges(); return(true); }
public bool insert(MoodyContext db, [FromBody] Producer producer) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); db.Producer.Add(new Producer { CompanyName = producer.CompanyName, Owner = producer.Owner, Address = producer.Address, LastModifyAt = DateTime.Now, LastModifyBy = admin.UserId }); db.SaveChanges(); return(true); }
public bool RemoveFromPlayList(MoodyContext db, int id) { Member member = HttpContext.Session.Get <Member>("MEMBER"); bool deleted = false; if (member != null) { try { db.Playlist.Remove(db.Playlist.Where(a => (a.SongId == id && a.UserId == member.UserId)).First()); db.SaveChanges(); deleted = true; } catch (Exception) { } } return(deleted); }
public bool update(MoodyContext db, [FromBody] Artist artist) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); Artist t = db.Artist.Where(a => a.ArtistCode == artist.ArtistCode).First(); t.FirstName = artist.FirstName; t.MiddleName = artist.MiddleName; t.LastName = artist.LastName; t.Biography = artist.Biography; t.Introduce = artist.Introduce; t.Band = artist.Band; t.BirthDate = artist.BirthDate; t.ProducerCode = artist.ProducerCode; t.LastModifyAt = DateTime.Now; t.LastModifyBy = admin.UserId; db.SaveChanges(); return(true); }
public bool update(MoodyContext db, [FromBody] Member member) { Member logged = HttpContext.Session.Get <Member>("MEMBER"); if (logged.UserId != member.UserId) { return(false); } Member t = db.Member.Where(u => u.UserId == logged.UserId).First(); t.FirstName = member.FirstName; t.MiddleName = member.MiddleName; t.LastName = member.LastName; t.Password = member.Password; db.SaveChanges(); HttpContext.Session.Set <Member>("MEMBER", t); return(true); }
public bool insert(MoodyContext db, [FromBody] Member member) { member.Username = member.Username.Trim(); member.Password = member.Password.Trim(); if (member.Username == "" || member.Password == "") { return(false); } if (db.Member.Any(m => m.Username == member.Username)) { return(false); } db.Member.Add(new Member { Username = member.Username, Password = member.Password }); db.SaveChanges(); return(true); }
public bool update(MoodyContext db, [FromBody] Administrator member) { Administrator logged = HttpContext.Session.Get <Administrator>("ADMIN"); if (logged.UserId != member.UserId) { return(false); } Administrator t = db.Administrator.Where(a => a.UserId == logged.UserId).First(); t.FirstName = member.FirstName; t.MiddleName = member.MiddleName; t.LastName = member.LastName; t.Password = member.Password; t.LastModifyAt = DateTime.Now; db.SaveChanges(); HttpContext.Session.Set <Administrator>("ADMIN", t); return(true); }
public bool insert(MoodyContext db, [FromBody] Artist artist) { Administrator admin = HttpContext.Session.Get <Administrator>("ADMIN"); db.Artist.Add(new Artist { FirstName = artist.FirstName, MiddleName = artist.MiddleName, LastName = artist.LastName, Biography = artist.Biography, Introduce = artist.Introduce, Band = artist.Band, BirthDate = artist.BirthDate, ProducerCode = artist.ProducerCode, LastModifyAt = DateTime.Now, LastModifyBy = admin.UserId }); db.SaveChanges(); return(true); }
public bool AddToPlayList(MoodyContext db, int id) { Member member = HttpContext.Session.Get <Member>("MEMBER"); bool added = false; if (member != null) { Playlist item = new Playlist { SongId = id, UserId = member.UserId }; try { db.Playlist.Add(item); db.SaveChanges(); added = true; } catch (Exception) { } } return(added); }
public bool delete(MoodyContext db, [FromBody] Category category) { db.Category.Remove(db.Category.Where(c => c.TagCode == category.TagCode).First()); db.SaveChanges(); return(true); }
public bool delete(MoodyContext db, [FromBody] Producer producer) { db.Producer.Remove(db.Producer.Where(a => a.ProducerCode == producer.ProducerCode).First()); db.SaveChanges(); return(true); }
public bool delete(MoodyContext db, [FromBody] Album album) { db.Album.Remove(db.Album.Where(a => a.AlbumId == album.AlbumId).First()); db.SaveChanges(); return(true); }
public bool delete(MoodyContext db, [FromBody] Artist artist) { db.Artist.Remove(db.Artist.Where(a => a.ArtistCode == artist.ArtistCode).First()); db.SaveChanges(); return(true); }