public void AddOrderedDish(Ordered_Dish Odish)//adds an ordered dish { if (Odish.amountOfDish <= 0) { throw new Exception("amount of dish isn't possible.. "); } float p = totalprice(Odish.orderNumber);//total price be4 adding the new dish Dish d = dal.listDishes(s => s.dishNumber == Odish.dishNumber).FirstOrDefault(); Order o = dal.listOreders(s => s.orderNumber == Odish.orderNumber).FirstOrDefault(); DateTime dd = DateTime.Now; DateTime ed = o.date; if (ed.Year < dd.Year || (ed.Year == dd.Year && ed.Month < dd.Month) || (ed.Year == dd.Year && ed.Month == dd.Month && ed.Day < dd.Day)) { throw new Exception("cant add ordered dish to an old order"); } Branch b = dal.listBranch(t => t.branchNumber == o.branchNumber).FirstOrDefault(); Ordered_Dish od = dal.listorderedDishes(s => (s.dishNumber == Odish.dishNumber) && (s.orderNumber == Odish.orderNumber)).FirstOrDefault(); if ((p + (d.dishPrice * Odish.amountOfDish)) > o.MaxPriceOfOrder)//checking that the total order pride isn't out of range { throw new Exception("cannot add dish,price of order is out of range "); } else if (b.branchAvailableDeliveryGuys - o.numWorkers < 0) { throw new Exception("cannot add dish,there aren't enough workers in the branch for this order "); } else if (d.Hechsher < o.Hechsher)//if the hechsher of the dish is lower than the hechsher of the order { // throw exception throw new Exception("cannot add dish,hechsher isn't good enough... "); } else if (!(dishExistInList(Odish.dishNumber) && branchExistInList(o.branchNumber)))//dish or branch do not exist { throw new Exception("cannot add dish,the dish or the branch don't exist... "); } if (od == null) { dal.AddOrderedDish(Odish); } else { Ordered_Dish odnew = new Ordered_Dish(od.dishNumber, od.orderNumber, od.amountOfDish + Odish.amountOfDish); dal.SetOrderedDish(odnew); } }