Пример #1
0
        public async Task UpdateDeliveryMen2(DeliveryMen DeliveryMen1)
        {
            using (var db = new DALContext())
            {
                DeliveryMen del = db.DeliveryMenList.FirstOrDefault(deliverym => deliverym.ID == DeliveryMen1.ID);

                Distribution[] newlist = new Distribution[del.DistributionList.Count];

                del.DistributionList.CopyTo(newlist, 0);
                foreach (var item in newlist)
                {
                    del.DistributionList.Remove(item);
                }
                db.DeliveryMenList.AddOrUpdate(DeliveryMen1);
                await db.SaveChangesAsync();

                for (int i = 0; i < newlist.Length; i++)
                {
                    Assignation(newlist[i], DeliveryMen1);
                }

                await db.SaveChangesAsync();



                //}
            }
        }
Пример #2
0
        public async Task AddDeliveryMen(DeliveryMen DeliveryMen1)
        {
            using (var db = new DALContext())
            {
                bool isexisting = false;
                foreach (var item in db.DeliveryMenList)
                {
                    if (item.ID == DeliveryMen1.ID)
                    {
                        isexisting = true;
                    }
                }
                if (DeliveryMen1 == null || isexisting == true)
                {
                    throw new Exception("the DeliveryMen that you want to add is empty or already existing");
                }
                bool problem = true;
                if (!(DeliveryMen1.telephone == "") && (DeliveryMen1.telephone.Substring(0, 1) == "0" || DeliveryMen1.telephone.Substring(0, 1) == "+" || DeliveryMen1.telephone.Substring(0, 1) == "*") && (DeliveryMen1.telephone.Length == 10 || DeliveryMen1.telephone.Length == 13 || DeliveryMen1.telephone.Length == 5))
                {
                    problem = false;
                }
                if (problem)
                {
                    throw new Exception("You can't add a DeliveryMen without an valid phone number");
                }

                if (DeliveryMen1.mail.Contains("@") == false)
                {
                    throw new Exception("You can't add a DeliveryMen without an valid email address");
                }

                db.DeliveryMenList.Add(DeliveryMen1);
                await db.SaveChangesAsync();
            }
        }
Пример #3
0
 public async Task AddShop(Shop shop)
 {
     using (var db = new DALContext())
     {
         db.Shops.Add(shop);
         await db.SaveChangesAsync();
     }
 }
Пример #4
0
 public async Task AddIceCream(IceCream iceCream)
 {
     using (var db = new DALContext())
     {
         db.IceCreams.Add(iceCream);
         await db.SaveChangesAsync();
     }
 }
Пример #5
0
        public async Task DeleteIceCream(int iceCreamID)
        {
            using (var db = new DALContext())
            {
                IceCream a = await db.IceCreams.FindAsync(iceCreamID);

                db.Entry(a).State = EntityState.Deleted;
                await db.SaveChangesAsync();
            }
        }
Пример #6
0
        public async Task DeleteShop(int shopID)
        {
            using (var db = new DALContext())
            {
                Shop shop = await db.Shops.FindAsync(shopID);

                db.Entry(shop).State = EntityState.Deleted;
                await db.SaveChangesAsync();
            }
        }
Пример #7
0
        public async Task AddDistribution(Distribution Distribution1)
        {
            using (var db = new DALContext())
            {
                bool isexisting = false;
                foreach (var item in db.DistributionList)
                {
                    if (item.ID == Distribution1.ID)
                    {
                        isexisting = true;
                    }
                }
                if (Distribution1 == null && isexisting == true)
                {
                    throw new Exception("the DeliveryMen that you want to add is empty or already existing");
                }
                if (Distribution1.ClientList == null)
                {
                    throw new Exception("you must select at least one client to this distribution");
                }

                Client[] newlist = new Client[Distribution1.ClientList.Count];

                Distribution1.ClientList.CopyTo(newlist, 0);
                foreach (var item in newlist)
                {
                    Distribution1.ClientList.Remove(item);
                }
                db.DistributionList.Add(Distribution1);
                await db.SaveChangesAsync();

                for (int i = 0; i < newlist.Length; i++)
                {
                    Assignation2(newlist[i], Distribution1);
                }

                await db.SaveChangesAsync();
            }
        }
Пример #8
0
        public async Task UpdateShop(Shop newShop)
        {
            using (var db = new DALContext())
            {
                Shop oldShop = await db.Shops.SingleOrDefaultAsync(x => x.ID == newShop.ID);

                if (oldShop != null)
                {
                    if (oldShop.Supply.Count() > newShop.Supply.Count())
                    {
                        var deletedItems = oldShop.Supply.Where(i => newShop.Supply.Find(n => n.ID == i.ID) == null).ToList();

                        foreach (var item in deletedItems)
                        {
                            oldShop.Supply.Remove(item);
                        }

                        db.Shops.Remove(oldShop);
                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        foreach (var item in newShop.Supply)
                        {
                            if (oldShop.Supply.Find(x => x.ID == item.ID) == null)
                            {
                                oldShop.Supply.Add(item);
                            }
                        }
                    }
                }

                //db.Entry(oldShop).CurrentValues.SetValues(newShop);

                db.Shops.AddOrUpdate(newShop);
                await db.SaveChangesAsync();
            }
        }
Пример #9
0
 public async Task removeClient(Client client1)
 {
     if (client1 == null)
     {
         throw new Exception("the client that you want to remove doesn't exist ");
     }
     else
     {
         using (var db = new DALContext())
         {
             Client a = db.ClientList.Find(client1.ID);
             db.Entry(a).State = EntityState.Deleted;
             await db.SaveChangesAsync();
         }
     }
 }
Пример #10
0
        public async Task UpdateDistribution()
        {
            using (var db = new DALContext())
            {
                bool flag = false;
                foreach (var item in db.DistributionList)
                {
                    if (item.date < DateTime.Now)
                    {
                        item.isDone = true;
                    }
                }


                await db.SaveChangesAsync();
            }
        }
Пример #11
0
        public async Task setLocation(Client myobj)
        {
            using (var db = new DALContext())
            {
                (double lat, double lng) = (myobj.location.Latitude, myobj.location.Longitude);

                string addressClient = myobj.address.street + " " + myobj.address.city;
                if (myobj.address.street == "default" || myobj.address.city == "default")
                {
                    throw new Exception("the address is not a valid address");
                }
                (lat, lng) = await LocationHelper.GetLatLong(addressClient);



                myobj.location = new Microsoft.Maps.MapControl.WPF.Location(lat, lng);
                await db.SaveChangesAsync();
            }
        }
Пример #12
0
        public async Task UpdateIceCream(IceCream newIceCream)
        {
            using (var db = new DALContext())
            {
                IceCream oldIceCream = await db.IceCreams.SingleOrDefaultAsync(x => x.ID == newIceCream.ID);

                if (oldIceCream != null)
                {
                    foreach (var item in newIceCream.Ratings)
                    {
                        if (oldIceCream.Ratings.Find(x => x.ID == item.ID) == null)
                        {
                            oldIceCream.Ratings.Add(item);
                        }
                    }
                }

                db.IceCreams.AddOrUpdate(newIceCream);
                await db.SaveChangesAsync();
            }
        }
Пример #13
0
        public async Task removeDistribution(Distribution Distribution1)
        {
            if (Distribution1.ClientList.Count != 0)
            {
                throw new Exception("this distribution is already assigned");
            }
            if (Distribution1 == null)
            {
                throw new Exception("the distribution does'nt exist ");
            }
            else
            {
                using (var db = new DALContext())
                {
                    Distribution a = await db.DistributionList.FindAsync(Distribution1.ID);

                    db.Entry(a).State = EntityState.Deleted;
                    await db.SaveChangesAsync();
                }
            }
        }
Пример #14
0
        public async Task Assignation(Distribution mydist, DeliveryMen mydel)
        {
            using (var db = new DALContext())
            {
                Distribution dist = db.DistributionList.FirstOrDefault(distribution => distribution.ID == mydist.ID);
                if (dist == null)
                {
                    throw new ArgumentNullException("Doesn't exist");
                }

                DeliveryMen del = db.DeliveryMenList.FirstOrDefault(deliverym => deliverym.ID == mydel.ID);
                if (del == null)
                {
                    throw new ArgumentNullException("Doesn't exist");
                }

                del.DistributionList.Add(dist);

                await db.SaveChangesAsync();
            }
        }
Пример #15
0
        public async Task removeDeliveryMen(DeliveryMen delivery1)
        {
            if (GetDistributionList(delivery1).Count != 0)
            {
                throw new Exception("this delivery men is already assigned to a distribution,you can't remove it");
            }

            if (delivery1 == null)
            {
                throw new Exception("the delivery men that you want to add doesn't exist ");
            }
            //else
            //{
            using (var db = new DALContext())
            {
                DeliveryMen a = await db.DeliveryMenList.FindAsync(delivery1.ID);

                db.Entry(a).State = EntityState.Deleted;
                await db.SaveChangesAsync();
            }
            //}
        }
Пример #16
0
        public async Task updateClient(Client Client1)
        {
            using (var db = new DALContext())
            {
                if (Client1 == null)
                {
                    throw new Exception("the client that you want to update is empty ");
                }
                bool problem = true;
                if ((Client1.telephone.Substring(0, 1) == "0" || Client1.telephone.Substring(0, 1) == "+" || Client1.telephone.Substring(0, 1) == "*") && (Client1.telephone.Length == 10 || Client1.telephone.Length == 13 || Client1.telephone.Length == 5))
                {
                    problem = false;
                }
                if (problem)
                {
                    throw new Exception("You can't update a client without an valid phone number");
                }

                if (Client1.mail.Contains("@") == false)
                {
                    throw new Exception("You can't update a client without an valid email address");
                }

                bool flag = false;
                foreach (var item in db.ClientList)
                {
                    if (item.ID == Client1.ID)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    db.ClientList.AddOrUpdate(Client1);
                    await db.SaveChangesAsync();
                }
            }
        }