Пример #1
0
        private void OnButtonUpdateClick(object sender, EventArgs e)
        {
            if (lvDeliveries.SelectedItems.Count != 1)
            {
                MessageBox.Show("Please select one delivery.", Constant.StoreAppName);
                return;
            }

            Deliveries delivery = (Deliveries)lvDeliveries.SelectedItems[0].Tag;

            UnitOfWork unitOfWork = new UnitOfWork(new StoreAppDBEntities());

            delivery = unitOfWork.Deliveries.Get(delivery.DeliveryId);

            var dialog = new FormDeliveryDialog(delivery, unitOfWork);

            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            int entriesWritten = unitOfWork.Complete();

            if (entriesWritten == 0)
            {
                MessageBox.Show("There was a problem updating the delivery.", Constant.StoreAppName);
                return;
            }

            UpdateListView(delivery, ListViewAction.Update, lvDeliveries.SelectedItems[0].Index);
        }
Пример #2
0
        private void OnButtonAddClick(object sender, EventArgs e)
        {
            var delivery = new Deliveries();
            var dialog   = new FormDeliveryDialog(delivery, _unitOfWork);

            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            _unitOfWork.Deliveries.Add(delivery);
            int entriesWritten = _unitOfWork.Complete();

            if (entriesWritten == 0)
            {
                MessageBox.Show("There was a problem adding a new delivery.", Constant.StoreAppName);
                return;
            }

            UpdateListView(delivery, ListViewAction.Add, Constant.IndexNone);
        }