Example #1
0
 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();
         }
     }
 }
Example #2
0
        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();
                }
            }
        }
Example #3
0
        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();
            }
        }