public bool updateOrderDetails(Int16 orderId, string produs, Decimal valoare, Int16 serial) { bool update = false; using (var testEntities = new TestEntities()) { ORDERDETAILS orderD = new ORDERDETAILS(); orderD.ORDERID = orderId; orderD.SERIAL = serial; var order2 = testEntities.ORDERDETAILS.First(o => (o.ORDERID == orderD.ORDERID && o.SERIAL == orderD.SERIAL)); order2.PRODUS = produs; order2.VALOARE = valoare; testEntities.SaveChanges(); update = true; } return(update); }
public bool updateCostumer(Int16 id, string name, string adr) { bool updateit = false; using (var testEntities = new TestEntities()) { CUSTOMER c = new CUSTOMER(); c.CUSTOMERID = id; //selectam clientul din bd var costumer = testEntities.CUSTOMER.First(cost => cost.CUSTOMERID == c.CUSTOMERID); if ((CUSTOMER)costumer != null) { ((CUSTOMER)costumer).NAME = name; ((CUSTOMER)costumer).ADRESA = adr; testEntities.SaveChanges(); updateit = true; } } return(updateit); }
public bool deleteOrder(Int16 id, DateTime data = new DateTime()) { bool del = false; if (id != -1) { using (var testEntities = new TestEntities()) { var order = testEntities.ORDER.First(o => o.ORDERID == id); //selectam toate detaliile acetei comenzi var orderDetails = from od in testEntities.ORDERDETAILS where od.ORDERID == order.ORDERID select od; foreach (var orderD in orderDetails) { testEntities.ORDERDETAILS.DeleteObject(orderD); } // stergem si comanda testEntities.ORDER.DeleteObject(order); testEntities.SaveChanges(); del = true; } } else // stergem toate comenzile efectuate pe data date { using (var testEntities = new TestEntities()) { var orders = from o in testEntities.ORDER where o.DATA == data select o; foreach (var order in orders) { var orderDetails = from od in testEntities.ORDERDETAILS where od.ORDERID == order.ORDERID select od; foreach (var orderD in orderDetails) { testEntities.ORDERDETAILS.DeleteObject(orderD); } testEntities.ORDER.DeleteObject(order); } testEntities.SaveChanges(); del = true; } } return(del); }
public bool addOrderDetails(Int16 orderId, string produs, Decimal valoare, Int16 serial) { using (var testEntities = new TestEntities()) { ORDERDETAILS orderD = new ORDERDETAILS(); orderD.ORDERID = orderId; orderD.SERIAL = serial; if (testEntities.ORDERDETAILS.Where(x => (x.ORDERID == orderD.ORDERID || x.SERIAL == orderD.SERIAL)).Count() <= 0) { orderD.PRODUS = produs; orderD.VALOARE = valoare; testEntities.AddToORDERDETAILS(orderD); testEntities.SaveChanges(); } else { return(false); } } return(true); }
public bool updateOrder(Int16 id, DateTime data, Int16 costumerId, Decimal valoare = -1) { bool update = false; using (var testEntities = new TestEntities()) { var order = testEntities.ORDER.First(o => o.ORDERID == id); if ((ORDER)order != null) { ((ORDER)order).DATA = data; ((ORDER)order).CUSTOMERID = costumerId; if (valoare != -1) { ((ORDER)order).VALOARE = valoare; } testEntities.SaveChanges(); update = true; } } return(update); }
public bool addCostumer(Int16 id, string name, string adress = "") { using (var testEntities = new TestEntities()) { CUSTOMER c = new CUSTOMER(); c.CUSTOMERID = id; // verificam daca mai exista un asemena id in bd if (testEntities.CUSTOMER.Where(x => x.CUSTOMERID == c.CUSTOMERID).Count() <= 0) { c.NAME = name; c.ADRESA = adress; testEntities.AddToCUSTOMER(c); testEntities.SaveChanges(); } else { return(false); } } return(true); // clientul a fost adauga }
public bool deleteOrderDetails(Int16 orderId, string produs, Int16 serial) { bool delete = false; if (orderId != -1) { using (var testEntities = new TestEntities()) { var orderD = testEntities.ORDERDETAILS.First(od => od.ORDERID == orderId); testEntities.ORDERDETAILS.DeleteObject(orderD); testEntities.SaveChanges(); delete = true; } } else if (serial != -1) { using (var testEntities = new TestEntities()) { var orderD = testEntities.ORDERDETAILS.First(od => od.SERIAL == serial); testEntities.ORDERDETAILS.DeleteObject(orderD); testEntities.SaveChanges(); delete = true; } } else { using (var testEntities = new TestEntities()) { var orderDs = from od in testEntities.ORDERDETAILS.Where(od => od.PRODUS == produs) select od; foreach (var orderd in orderDs) { testEntities.ORDERDETAILS.DeleteObject(orderd); } testEntities.SaveChanges(); delete = true; } } return(delete); }