Exemplo n.º 1
0
 public static bool DeleteClient(int number)
 {
     using (var db = new TravelAgencyContext())
     {
         int    count  = db.Clients.Count();
         Client client = null;
         client = db.Clients.Where(x => x.ClientNumber == number).First();
         db.Clients.Remove(client);
         try
         {
             db.SaveChanges();
         }
         catch (DbUpdateException ex)
         {
             throw ex;
         }
         if (db.Clients.Count() + 1 == count)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 2
0
 public static void UpdateWorker(Worker worker)
 {
     using (var db = new TravelAgencyContext())
     {
         db.Entry(worker).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
        public static Worker SelectServiceWorker(Order order)
        {
            Worker worker = null;

            using (var db = new TravelAgencyContext())
            {
                if (db.Orders.Count() > 0)
                {
                    worker = db.Orders.Where(x => x.OrderNumber == order.OrderNumber).First().ServiceWorker;
                }
            }
            return(worker);
        }
Exemplo n.º 4
0
        public static List <Client> SelectClients()
        {
            List <Client> list = new List <Client>();

            using (var db = new TravelAgencyContext())
            {
                if (db.Clients.Count() > 0)
                {
                    list = db.Clients.ToList();
                }
            }
            return(list);
        }
Exemplo n.º 5
0
        public static List <Offer> SelectOffers()
        {
            List <Offer> list = new List <Offer>();

            using (var db = new TravelAgencyContext())
            {
                if (db.Offers.Count() > 0)
                {
                    list = db.Offers.ToList();
                }
            }
            return(list);
        }
Exemplo n.º 6
0
        public static List <Order> SelectOrders()
        {
            List <Order> list = new List <Order>();

            using (var db = new TravelAgencyContext())
            {
                if (db.Orders.Count() > 0)
                {
                    list = db.Orders.Include(x => x.ServiceWorker).ToList();
                }
            }
            return(list);
        }
Exemplo n.º 7
0
        public static Order SelectOrderFromQuery(string query)
        {
            Order order = null;

            using (var db = new TravelAgencyContext())
            {
                if (db.Orders.Count() > 0)
                {
                    order = db.Orders.SqlQuery(query).ToList().First();
                }
            }
            return(order);
        }
Exemplo n.º 8
0
        public static Client SelectClientFromQuery(string query)
        {
            Client client = null;

            using (var db = new TravelAgencyContext())
            {
                if (db.Clients.Count() > 0)
                {
                    client = db.Clients.SqlQuery(query).ToList().First();
                }
            }
            return(client);
        }
Exemplo n.º 9
0
 public static bool InsertWorkerOrder(Order order, Worker worker)
 {
     using (var db = new TravelAgencyContext())
     {
         int count = db.Workers.Where(x => x.WorkerNumber == worker.WorkerNumber).First().WorkerOrders.Count;
         db.Workers.Where(x => x.WorkerNumber == worker.WorkerNumber).First().WorkerOrders.Add(order);
         db.SaveChanges();
         if (count + 1 == db.Workers.Where(x => x.WorkerNumber == worker.WorkerNumber).First().WorkerOrders.Count)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 10
0
 public static bool InsertClient(Client client)
 {
     using (var db = new TravelAgencyContext())
     {
         int count = db.Clients.Count();
         db.Clients.Add(client);
         db.SaveChanges();
         if (count + 1 == db.Clients.Count())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 11
0
 public static bool InsertOffer(Offer offer)
 {
     using (var db = new TravelAgencyContext())
     {
         int count = db.Offers.Count();
         db.Offers.Add(offer);
         db.SaveChanges();
         if (count + 1 == db.Offers.Count())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 12
0
 public static bool InsertOrder(Order order)
 {
     using (var db = new TravelAgencyContext())
     {
         int count = db.Orders.Count();
         db.Entry(order.ServiceWorker).State = EntityState.Unchanged;
         db.Orders.Add(order);
         db.SaveChanges();
         if (count + 1 == db.Orders.Count())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 13
0
        public static List <Order> SelectWorkerOrders(Worker worker)
        {
            List <Order> list = new List <Order>();

            using (var db = new TravelAgencyContext())
            {
                try
                {
                    if (db.Workers.Where(x => x.WorkerNumber == worker.WorkerNumber).First().WorkerOrders.Count() > 0)
                    {
                        list = db.Workers.Where(x => x.WorkerNumber == worker.WorkerNumber).First().WorkerOrders.ToList();
                    }
                }
                catch (InvalidOperationException)
                {
                    return(list);
                }
            }
            return(list);
        }