public String AddOrderDetails(OrderDetail od) { _gestionDb = new GcdbEntities(); if (IsOrderDetailsExist(od)) return "OrderDetails existe déjà"; _gestionDb.OrderDetails.Add(od); _gestionDb.SaveChanges(); return "OrderDetails ajouter avec succes"; }
public String DelOrderDetails(OrderDetail od) { _gestionDb = new GcdbEntities(); if (!IsOrderDetailsExist(od)) return "OrderDetails n'existante pas"; OrderDetail orderDetails = _gestionDb.OrderDetails.Single(od1 => (od1.OrderID == od.OrderID) && (od1.ProductID == od.ProductID)); _gestionDb.OrderDetails.Remove(orderDetails); _gestionDb.SaveChanges(); return "OrderDetails supprimer avec succes"; }
public String MajOrderDetails(OrderDetail od) { _gestionDb = new GcdbEntities(); OrderDetail orderDetails = _gestionDb.OrderDetails.Single(od1 => (od1.OrderID == od.OrderID) && (od1.ProductID == od.ProductID)); try { orderDetails = od; // si sa marche pas alors attache detache sinon affactation champ par champ } catch (Exception ) { return "erreur"; } return "OrderDetails modifier avec succes"; }
private static bool IsOrderDetailsExist(OrderDetail od) { try { GcdbEntities ggestionDb = new GcdbEntities(); var requete = from od1 in ggestionDb.OrderDetails where (od1.OrderID == od.OrderID) && (od1.ProductID == od.ProductID) select od1; return requete.Any(); } catch (Exception) { return false; } }
private void CreateVente(List<ProduitsSel> productSelSelected, string remarque, Customer customer, DateTime dateTime, decimal tvaValue, Employee newEmployee) { try { Customer getCustomer = gestionDb.Customers.FirstOrDefault(c => c.CustomerID==customer.CustomerID); if(getCustomer!=null) { Order newOrder = new Order { OrderDate = dateTime, CommandeDate = dateTime, CustomerID = getCustomer.CustomerID, Customer = getCustomer, TvaValue = tvaValue, Description = remarque, Status = 0, }; foreach (var entity in productSelSelected) { OrderDetail newOrderDetail = new OrderDetail { ProductID = entity.TheProduct.ProductID, Quantity = (int) entity.UnitsOnOrder, UnitPrice = entity.UnitePrice, TotalPrice = entity.TotalPrice, }; newOrder.OrderDetails.Add(newOrderDetail); } gestionDb.Orders.Add(newOrder); gestionDb.SaveChanges(); theOrder= newOrder; } else theOrder = null; } catch (Exception exe) { MessageBox.Show(exe.ToString()); theOrder= null; } }