public void Update(User model) { if (model == null || model.ID < 1) { throw new ArgumentException("Mode is not valid."); } using (ChordsDBEntities1 db = new ChordsDBEntities1()) { User modelFromDB = db.Users.FirstOrDefault(e => e.ID == model.ID); if (modelFromDB == null) { throw new NullReferenceException("Model by given ID doesn't exist at database."); } modelFromDB.Email = model.Email; modelFromDB.First_Name = model.First_Name; modelFromDB.Last_Name = model.Last_Name; modelFromDB.Password = model.Password; db.Entry(modelFromDB).State = EntityState.Modified; db.SaveChanges(); } }
public void Update(Song model) { if (model == null || model.ID < 1) { throw new ArgumentException("Mode is not valid."); } using (ChordsDBEntities1 db = new ChordsDBEntities1()) { Song modelFromDB = db.Songs.FirstOrDefault(e => e.ID == model.ID); if (modelFromDB == null) { throw new NullReferenceException("Model by given ID doesn't exist at database."); } modelFromDB.Permission = model.Permission; modelFromDB.Language = model.Language; modelFromDB.Lyrics = model.Lyrics; modelFromDB.Comments = model.Comments; modelFromDB.Chords = model.Chords; modelFromDB.Name = model.Name; db.Entry(modelFromDB).State = EntityState.Modified; db.SaveChanges(); } }
public void Delete(int id) { using (ChordsDBEntities1 db = new ChordsDBEntities1()) { User user = db.Users.FirstOrDefault(x => x.ID == id); if (user == null) { throw new NullReferenceException("Attempt to remove item that doesn't exist in database."); } db.Users.Remove(user); db.Entry(user).State = EntityState.Deleted; db.SaveChanges(); } }