public void DeactiveOrder(OrderPrimitive orderPrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              Order order = orderPrimitive.GetEntity();

              Order existingObject = context.Orders.Where(x => x.Id == order.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null)
              {
            throw new Exception("Only exists delivery note can be canceled.");
              }

              order.Deactivated = DateTime.Now;
              context.Orders.ApplyCurrentValues(order);

              context.SaveChanges();
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }
        public void CreateOrUpdateOrder(OrderPrimitive orderPrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {

              Order order = orderPrimitive.GetEntity();
              Order existingObject = context.Orders.Where(x => x.Id == order.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null && order.Id > 0)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")),
                                                        "Obiekt nie istniał w bazie, a jego Id jest większe od 0.");
              }

              //Item has no PK value, must be new);
              if (order.Id <= 0)
              {
            order.DateOfOrder = DateTime.Now;
            context.Orders.AddObject(order);
              }
              //Item was retrieved, and the item passed has a valid ID, do an update
              else
              {
            context.Orders.ApplyCurrentValues(order);
              }

              context.SaveChanges();

            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }