Beispiel #1
0
        public void DeleteTest()
        {
            Supplier v = new Supplier();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.SupplierName  = "bem";
                v.Contract      = "uQte8AWkm";
                v.ContractPhone = "OX9Psxo";
                context.Set <Supplier>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString());

            Assert.IsInstanceOfType(rv.Model, typeof(SupplierVM));

            SupplierVM vm = rv.Model as SupplierVM;

            v         = new Supplier();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID.ToString(), null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <Supplier>().Count(), 1);
            }
        }
        public async Task SoftDeleteSupplier_Success_ReturnStatusCodeOk()
        {
            IHttpActionResult result = await supplierController.Delete(new Guid("bbbf396b-5b78-4924-bd21-a9afa9decfc8"));

            HttpJsonApiResult <SupplierViewModel> contentResult = result as HttpJsonApiResult <SupplierViewModel>;

            Assert.AreEqual(HttpStatusCode.OK, contentResult.StatusCode);
        }
Beispiel #3
0
 private void bwRemove_DoWork(object sender, DoWorkEventArgs e)
 {
     foreach (var removeItem in supplierToRemoveList)
     {
         SupplierController.Delete(removeItem.SupplierID);
         supplierCurrentList.Remove(removeItem);
     }
 }
        public void Delete([Values(53)] int id)
        {
            _controller.Request.Method = HttpMethod.Delete;

            var actual = _controller.Delete(id, 0) as OkNegotiatedContentResult <string>;

            Assert.IsNotNull(actual);
        }
Beispiel #5
0
        private void btnSupplierDelete_Click(object sender, EventArgs e)
        {
            var result = _supplierController.Delete(lstSuppliers.SelectedItem as Supplier);

            if (!result)
            {
                MessageBox.Show("Could not Delete Selected Supplier");
            }

            lstSuppliers.DataSource = _supplierController.Read();
        }
Beispiel #6
0
        public void DeleteTest()
        {
            var controller = new SupplierController();
            var supplier   = new Supplier
            {
                Id   = 1,
                Name = "Mouse",
            };

            controller.Post(supplier);
            controller.Delete(supplier.Id);
            Assert.IsTrue(controller.suppliers.Count == 0);
        }
Beispiel #7
0
        private void deleteBtn_Click(object sender, EventArgs e)
        {
            int id = int.Parse(IdText.Text);

            if (controller.Delete(id))
            {
                MessageBox.Show(null, "Supplier deleted successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //refresh table
                dataGrid.DataSource = controller.ViewAll();
            }
            else
            {
                MessageBox.Show(null, "Something went wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #8
0
        public void ShouldDeleteSupplier()
        {
            Console.WriteLine("Initalizing Supplier Delete View");
            var controller           = new SupplierController(client);
            var currentSupplierCount = suppliers.Count;

            Console.WriteLine($"Before deleting supplier: No of suppliers-{currentSupplierCount}");
            var supplier = suppliers.FirstOrDefault(x => x.Code == "S001");

            Assert.IsNotNull(supplier);
            Console.WriteLine($"Supplier to delete: Code-{supplier.Code} Name-{supplier.Name} Address-{supplier.Address}");
            var result = controller.Delete("S001");

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual(currentSupplierCount - 1, suppliers.Count);
            Console.WriteLine($"After deleting supplier: No of suppliers-{suppliers.Count}");
            var added = suppliers.FirstOrDefault(x => x.Code == "S001");

            Assert.IsNull(added);
        }
Beispiel #9
0
        private void dataGridViewSuppliers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex == -1) //редактрование с второй строки
                {
                    return;
                }
                int taskIndex = dataGridViewSuppliers.Rows[e.RowIndex].Cells["Операция"].ColumnIndex;

                if (e.ColumnIndex == taskIndex)
                {
                    string task = dataGridViewSuppliers.Rows[e.RowIndex].Cells["Операция"].Value.ToString();

                    if (task == "Удалить")
                    {
                        if (MessageBox.Show("Удалить эту строку?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            int id = (int)dataGridViewSuppliers.CurrentRow.Cells["ID"].Value;
                            supplierController.Delete(id);
                        }
                    }
                    else if (task == "Добавить")
                    {
                        int             rowIndex   = dataGridViewSuppliers.Rows.Count - 2;
                        DataGridViewRow currentRow = dataGridViewSuppliers.Rows[rowIndex];

                        Supplier newSupplier = GetSupplierInfo(ref currentRow);
                        if (newSupplier == null)
                        {
                            return;
                        }

                        if (newSupplier.Phone.Length > 11)
                        {
                            MessageBox.Show("Номер телефона должен состоять не более чем из 11 цифр.");
                            return;
                        }

                        int currentSupplierId = supplierController.GetSupplierIdByPhone(newSupplier.Phone);
                        if (currentSupplierId != 0)
                        {
                            MessageBox.Show("Поставщик с введенным номером телефона уже существует.");
                            return;
                        }

                        supplierController.Add(newSupplier);

                        dataGridViewSuppliers.Rows[e.RowIndex].Cells["Операция"].Value = "Удалить";
                    }
                    else if (task == "Изм.")
                    {
                        int             rowIndex   = e.RowIndex;
                        DataGridViewRow currentRow = dataGridViewSuppliers.Rows[rowIndex];

                        Supplier updatedSupplier = GetSupplierInfo(ref currentRow);
                        if (updatedSupplier == null)
                        {
                            return;
                        }

                        int currentSupplierId = supplierController.GetSupplierIdByPhone(updatedSupplier.Phone);
                        if (updatedSupplier.ID != currentSupplierId && currentSupplierId != 0)
                        {
                            MessageBox.Show("Поставщик с введенным номером телефона уже существует.");
                            return;
                        }

                        supplierController.Edit(updatedSupplier);

                        currentRow.Cells["Операция"].Value = "Удалить";
                    }

                    supplierController.GetAllSuppliers(ref dataGridViewSuppliers);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void Supplier_DeleteSupplierNoIdPassed_BadRequest()
        {
            var result = supplierController.Delete(null) as HttpStatusCodeResult;

            Assert.AreEqual(400, result.StatusCode);
        }