Exemplo n.º 1
0
        //The function adds a delivery man to the data base or updates it in case that the delivery man is already exist

        public void Add_DeliveryMan(DeliveryMan dm)
        {
            using (var ctx = new DeliveryContext())
            {
                try {
                    if (ctx.DeliveryMans.Find(dm.Id) != null)
                    {
                        var old = ctx.DeliveryMans.Find(dm.Id);
                        updateAddress(dm.Address);
                        old.FirstName   = dm.FirstName;
                        old.LastName    = dm.LastName;
                        old.PhoneNumber = dm.PhoneNumber;
                        old.Email       = dm.Email;
                        ctx.SaveChanges();
                    }
                    else
                    {
                        ctx.Addresses.Add(dm.Address);
                        ctx.DeliveryMans.Add(dm);
                        ctx.SaveChanges();
                    }
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }
        }
Exemplo n.º 2
0
 //The function adds an adult to the data base or updates it in case that the adult is already exist
 public void Add_Adult(Adult adult)
 {
     using (var ctx = new DeliveryContext())
     {
         try
         {
             if (ctx.Adults.Find(adult.Id) != null)
             {
                 var old = ctx.Adults.Find(adult.Id);
                 updateAddress(adult.Address);
                 old.FirstName   = adult.FirstName;
                 old.LastName    = adult.LastName;
                 old.PhoneNumber = adult.PhoneNumber;
                 old.Medicine    = adult.Medicine;
                 old.Food        = adult.Food;
                 ctx.SaveChanges();
             }
             else
             {
                 ctx.Addresses.Add(adult.Address);
                 ctx.Adults.Add(adult);
                 ctx.SaveChanges();
             }
         }
         catch { MessageBox.Show("Unable to connect to DataBase"); }
     }
 }
Exemplo n.º 3
0
        //The function returns a list of all deliveries from the data base
        public IEnumerable <Delivery> Get_all_Deliveries()
        {
            List <Delivery> result = new List <Delivery>();

            using (var context = new DeliveryContext())
            {
                try {
                    result = context.Deliveries.Include(a => a.MyAdult).Include(c => c.MyAdult.Address).Include(b => b.MyDeliveryMan).Include(d => d.MyDeliveryMan.Address).ToList <Delivery>();
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }
            return(result);
        }
Exemplo n.º 4
0
        //The function returns all the managers from the data base

        public IEnumerable <Manager> Get_all_Managers()
        {
            List <Manager> result = new List <Manager>();

            using (var context = new DeliveryContext())
            {
                try {
                    result = context.Managers.ToList <Manager>();
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }
            return(result);
        }
Exemplo n.º 5
0
        //The function returns a list of all delivery men from the data base
        public IEnumerable <DeliveryMan> Get_all_DeliveryMans()
        {
            List <DeliveryMan> result = new List <DeliveryMan>();

            using (var context = new DeliveryContext())
            {
                try {
                    result = context.DeliveryMans.Include(a => a.Address).ToList <DeliveryMan>();
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }

            return(result);
        }
Exemplo n.º 6
0
        //The function returns a list of all adult from the data base
        public List <Adult> Get_all_Adults()
        {
            List <Adult> result = new List <Adult>();

            using (var context = new DeliveryContext())
            {
                try
                {
                    result = context.Adults.Include(a => a.Address).ToList <Adult>();
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }
            return(result);
        }
Exemplo n.º 7
0
 //The function receives a delivery and defines it as "Done"
 public void IsTaskDone(List <Delivery> deliveries)
 {
     using (var context = new DeliveryContext())
     {
         try {
             foreach (var delivery in deliveries)
             {
                 var old = context.Deliveries.Find(delivery.Code);
                 old.IsDone = delivery.IsDone;
             }
             context.SaveChanges();
         }
         catch { MessageBox.Show("Unable to connect to DataBase"); }
     }
 }
Exemplo n.º 8
0
        //The function update an address by another parameter of address
        private void updateAddress(Address address)
        {
            using (var ctx = new DeliveryContext())
                try
                {
                    if (ctx.Addresses.Find(address.AddressID) != null)
                    {
                        var old = ctx.Addresses.Find(address.AddressID);

                        old.Street         = address.Street;
                        old.BuildingNumber = address.BuildingNumber;
                        old.City           = address.City;

                        ctx.SaveChanges();
                    }
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
        }
Exemplo n.º 9
0
        //The function adds a delivery to the data base or updates it in case that the delivery is already exist

        public void Add_Delivery(Delivery delivery)
        {
            using (var ctx = new DeliveryContext())
            {
                try {
                    var deliveryMan = ctx.DeliveryMans.Find(delivery.MyDeliveryMan.Id);
                    var adult       = ctx.Adults.Find(delivery.MyAdult.Id);
                    delivery.MyAdult       = null;
                    delivery.MyDeliveryMan = null;
                    ctx.Deliveries.Add(delivery);
                    ctx.SaveChanges();

                    var deliveryToUpdate = ctx.Deliveries.Find(delivery.Code);
                    deliveryToUpdate.MyAdult       = adult;
                    deliveryToUpdate.MyDeliveryMan = deliveryMan;
                    ctx.SaveChanges();
                }
                catch { MessageBox.Show("Unable to connect to DataBase"); }
            }
        }