/// <summary>
        /// Deletes the <see cref="DeliveryNote"/>.
        /// </summary>
        /// <param name="deliveryNote">The delivery note which will be canceled.</param>
        public void ActiveDeliveryNote(DeliveryNotePrimitive deliveryNotePrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              DeliveryNote deliveryNote = deliveryNotePrimitive.GetEntity();

              DeliveryNote existingObject = context.DeliveryNotes.Where(x => x.Id == deliveryNote.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.");
              }

              deliveryNote.DeactivationReason = string.Empty;
              deliveryNote.Deactivated = null;
              context.DeliveryNotes.ApplyCurrentValues(deliveryNote);

              context.SaveChanges();
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }
        /// <summary>
        /// Updates the <see cref="DeliveryNote"/>.
        /// </summary>
        /// <param name="deliveryNote">The delivery note which will be updated.</param>
        public DeliveryNotePrimitive CreateOrUpdateDeliveryNote(DeliveryNotePrimitive deliveryNotePrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              DeliveryNote deliveryNote = deliveryNotePrimitive.GetEntity();

              DeliveryNote existingObject = context.DeliveryNotes.Where(x => x.Id == deliveryNote.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null && deliveryNote.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.");
              }

              DeliveryNote checkingNumber =
            context.DeliveryNotes.Where(x => x.Number == deliveryNote.Number && x.Year == deliveryNote.Year).
              FirstOrDefault();

              //Item has no PK value, must be new);)
              if (deliveryNote.Id <= 0)
              {
            deliveryNote.DateDrawing = DateTime.Now;
            //deliveryNote.Number = GetNextDeliveryNumber();
            if (checkingNumber != null)
            {
              throw new Exception("Ten numer WZ'tki juz istnieje!");
            }
            context.DeliveryNotes.AddObject(deliveryNote);

              }
              //Item was retrieved, and the item passed has a valid ID, do an update
              else
              {
            if (checkingNumber != null && checkingNumber.Id != deliveryNote.Id)
            {
              throw new Exception("Ten numer WZ'tki juz istnieje!");
            }
            context.DeliveryNotes.ApplyCurrentValues(deliveryNote);
              }

              context.SaveChanges();

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