private void dataGridViewProviderInvoice_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DeliveryQuery deliveryQuery = new DeliveryQuery();
            int           goToDelivery  = 0;

            foreach (DataGridViewRow row in dataGridViewProviderInvoice.SelectedRows)
            {
                goToDelivery = int.Parse(row.Cells[6].Value.ToString());
            }
            if (goToDelivery != 0)
            {
                const string message =
                    "Czy chcesz przejść do dostawy";
                const string caption = "Edycja";
                var          result  = MessageBox.Show(message, caption,
                                                       MessageBoxButtons.OKCancel,
                                                       MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    var delivery = context.Delivery.FirstOrDefault(d => d.deliveryID == goToDelivery);
                    deliveryQuery.delivery = delivery.deliveryNoteID;
                    FormCheckDelivery formCheckDelivery = new FormCheckDelivery(delivery.deliveryNoteID, id);
                    formCheckDelivery.Show();
                    this.Hide();
                }
            }
        }
        private void ManageDelivery(DeliveryQuery query)
        {
            Delivery delivery = Transform(query);

            if (string.IsNullOrEmpty(delivery.Subject) || string.IsNullOrEmpty(delivery.Body) || delivery.Recipients == null || !delivery.Recipients.Any())
            {
                throw new ArgumentNullException();
            }

            bool isNew = string.IsNullOrWhiteSpace(delivery.Id);

            if (isNew)
            {
                delivery.CreationDate = DateTime.UtcNow;

                _deliveryRepository.Add(delivery);

                if (query.StartNow)
                {
                    _sendService.SendMessage(delivery);
                }
            }
            else
            {
                _deliveryRepository
                    .Update(delivery.Id)
                    .Set(x => x.Title, delivery.Title)
                    .Set(x => x.Subject, delivery.Subject)
                    .Set(x => x.Body, delivery.Body)
                    .Set(x => x.Recipients, delivery.Recipients)
                    .Set(x => x.Status, delivery.Status)
                    .Apply();
            }
        }
        public void ChangeDelivery(DeliveryQuery query)
        {
            ValidateId(query.Id);

            ManageDelivery(query);
        }
 public void SaveDelivery(DeliveryQuery query)
 {
     ManageDelivery(query);
 }
        private Delivery Transform(DeliveryQuery query)
        {
            if (query.StartNow)
            {
                query.Status = DeliveryStatus.InProcess;
            }
            else
            {
                query.Status = DeliveryStatus.Wait;
            }

            return (Delivery)query;
        }