public static void DeleteSubscriber(int id) { using (var context = new PbxEntities()) { var subToRemove = context.Subscribers.SingleOrDefault(x => x.Id == id); if (subToRemove != null) { context.Subscribers.Remove(subToRemove); context.SaveChanges(); } } }
public static void UpdateSubscriber(int id, string name, string surname, string phoneNumber, string balance) { using (var context = new PbxEntities()) { var sub = context.Subscribers.SingleOrDefault(x => x.Id == id); if (sub != null) { sub.Name = name; sub.Surname = surname; sub.PhoneNumber = phoneNumber; sub.Balance = Convert.ToDecimal(balance); context.SaveChanges(); } } }
public static void AddSubscriber(string name, string surname, string phoneNumber) { if (!CheckIfUnique(phoneNumber)) { throw new Exception("The database already contains a subscriber with this phone number!"); } using (var context = new PbxEntities()) { context.Subscribers.Add(new Subscribers { Name = name, Surname = surname, PhoneNumber = phoneNumber }); context.SaveChanges(); } }