Exemple #1
0
 /// <summary>
 /// 删除一个供应商信息
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="id">一供应商信息的主键</param>
 /// <returns></returns>
 public bool Delete(ref ValidationErrors validationErrors, int id)
 {
     try
     {
         return(repository.Delete(id) == 1);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
        public void Delete_WithValidEntityID_ShouldRemoveRecordFromDatabase()
        {
            var options = ConnectionOptionHelper.Sqlite();
            //Arrange
            var supplier = new Supplier
            {
                Name        = "Shirt Supplier",
                Description = "This is a Shirt Supplier",
                IsActive    = true
            };

            using (var context = new ECommerceDbContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();
                var sut = new SupplierRepository(context);
                context.Suppliers.Add(supplier);
                context.SaveChanges();
                //Act
                sut.Delete(supplier.ID);
                context.SaveChanges();
                var actual = context.Suppliers.Find(supplier.ID);
                //Assert
                Assert.Null(actual);
            }
        }
Exemple #3
0
 public void Delete(object obj, EventArgs e)
 {
     try
     {
         if (m_supplier.ID > 0)
         {
             this.Cursor = Cursors.WaitCursor;
             if (KryptonMessageBox.Show("Are you sure to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
             {
                 this.Cursor = Cursors.Default; return;
             }
             r_sup.Delete(m_supplier);
             removeRecord(m_supplier.ID);
             ClearForm();
             setEnableForm(true);
             setEditMode(EditMode.New);
             textBoxCode.Focus();
             this.Cursor = Cursors.Default;
         }
     }
     catch (Exception x)
     {
         KryptonMessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
        public void Update_WithValidEntity_ShouldUpdateDatabaseRecord()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Melrose Mejidana",
                Description = "Shoe Supplier",
                IsActive    = true
            };

            Assert.True(supplier.ID != 0);

            supplier.Name        = "Myel Mejidana";
            supplier.Description = "Shoe Supplier will be hiatus";
            supplier.IsActive    = false;

            //Act
            sut.Update(supplier.ID, supplier);
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            Assert.Equal(supplier.Name, actual.Name);
            Assert.Equal(supplier.Description, actual.Description);
            Assert.Equal(supplier.IsActive, actual.IsActive);

            //Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #5
0
        public void Retrieve_WithSkipAndCount_ShouldReturnTheCorrectRecords()
        {
            // Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (var i = 1; i <= 10; i += 1)
            {
                sut.Create(new Supplier
                {
                    Name        = string.Format("Supplier {0}", i),
                    Description = string.Format("Supplier Description {0}.", i),
                    IsActive    = true
                });
            }

            // Act
            var list = sut.Retrieve(0, 5);

            // Assert
            Assert.True(list.Count() == 5);

            // Cleanup
            list = context.Suppliers.ToList();
            foreach (var item in list)
            {
                sut.Delete(item.ID);
            }
        }
Exemple #6
0
 public void Delete(int supplierId)
 {
     if (supplierId != null)
     {
         _supplierRepository.Delete(x => x.Id == supplierId);
     }
 }
        public void Retrieve_WithSkipAndCount_ShouldReturnValidList()
        {
            //Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (var i = 1; i <= 20; i += 1)
            {
                sut.Create(new Supplier {
                    Name        = string.Format("Supplier {0}", i),
                    Description = string.Format("Description {0}", i),
                    IsActive    = true
                });
            }

            //Act
            var list = sut.Retrieve(5, 5);

            //Assert
            Assert.True(list.Count() == 5);

            //Cleanup
            list = sut.Retrieve(0, int.MaxValue).ToList();
            foreach (var entity in list)
            {
                sut.Delete(entity.ID);
            }
        }
 public void Delete(int ID)
 {
     if (ModelState.IsValid)
     {
         SupplierRepository.Delete(ID);
     }
 }
        void suppliers_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Remove:
                foreach (SupplierView c in e.OldItems)
                {
                    supRepo.Delete(c.InnerSupplier);
                }
                break;

            case NotifyCollectionChangedAction.Add:
                foreach (SupplierView c in e.NewItems)
                {
                    supRepo.SaveOrUpdate(c.InnerSupplier);
                }
                break;

            default:
                foreach (SupplierView c in e.OldItems)
                {
                    supRepo.SaveOrUpdate(c.InnerSupplier);
                }
                break;
            }
        }
Exemple #10
0
        public void Retrieve_WithSkipAndCount_ReturnsTheCorrectPage()
        {
            //Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (int i = 0; i < 20; i += 1)
            {
                sut.Create(new Supplier
                {
                    Name        = string.Format("Supplier No. {0}", i),
                    Description = string.Format("Description No. {0}", i),
                    IsActive    = true
                });
            }
            //Act
            var actual = sut.Retrieve(4, 3);

            //Assert
            Assert.True(actual.Count() == 3);
            //Cleanup
            var list = sut.Retrieve(0, Int32.MaxValue);

            foreach (var item in list)
            {
                sut.Delete(item.ID);
            }
        }
Exemple #11
0
        public void Retrieve_ValidData_ShouldWork()
        {
            var      context             = new ECommerceDbContext();
            var      sut                 = new SupplierRepository(context);
            string   expectedName        = "Yakult Inc.";
            string   expectedDescription = "Lactobacillus Protectus";
            bool     expectedIsActive    = false;
            Supplier supplier            = new Supplier
            {
                Name        = expectedName,
                Description = expectedDescription,
                IsActive    = expectedIsActive
            };

            sut.Create(supplier);
            //Act
            var result = sut.Retrieve(supplier.ID);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(result.Name, expectedName);
            Assert.Equal(result.Description, expectedDescription);
            Assert.Equal(result.IsActive, expectedIsActive);
            //Cleanup
            sut.Delete(result.ID);
        }
Exemple #12
0
        public void Update_WithValidData_ShouldWork()
        {
            var      context             = new ECommerceDbContext();
            var      sut                 = new SupplierRepository(context);
            string   expectedName        = "Yakult Inc.";
            string   expectedDescription = "Lactobacillus Protectus";
            bool     expectedIsActive    = false;
            Supplier supplier            = new Supplier
            {
                Name        = "Jakult inc.",
                Description = "Lactobacillus Aysus",
                IsActive    = true
            };

            sut.Create(supplier);
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            actual.Name        = expectedName;
            actual.Description = expectedDescription;
            actual.IsActive    = expectedIsActive;
            sut.Update(actual.ID, actual);
            //Cleanup
            sut.Delete(actual.ID);
        }
Exemple #13
0
        public void Retrieve_WithSkipAndCount_Work()
        {
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (int i = 0; i < 30; i += 1)
            {
                Supplier supplier = new Supplier
                {
                    Name        = String.Format("Name {0}", i),
                    Description = String.Format("Description {0}", i),
                    IsActive    = true
                };
                sut.Create(supplier);
            }
            var list = sut.Retrieve(3, 3);

            Assert.True(3 == list.Count());//Pano machecheck kung na skip yung unang tatlo

            //Cleanup
            var listToBeDeleted = sut.Retrieve(0, Int32.MaxValue);

            foreach (Supplier supplier in listToBeDeleted)
            {
                sut.Delete(supplier.ID);
            }
        }
Exemple #14
0
        public void Update_WithValidProperty_ShouldUpdateEntity()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Supplier",
                IsActive    = true
            };

            sut.Create(supplier);
            var expected = sut.Retrieve(supplier.ID);

            //Act
            expected.Name        = "Blaster";
            expected.Description = "Software Engineer Supplier";
            sut.Update(supplier.ID, expected);
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            Assert.Equal(actual, expected);

            //Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #15
0
 public async Task <int> Delete(Supplier supplier)
 {
     using (var db = new CyzaTestEntities())
     {
         var repository = new SupplierRepository(db);
         repository.Delete(supplier);
         return(await db.SaveChangesAsync());
     }
 }
Exemple #16
0
        public IHttpActionResult Delete(int id)
        {
            var result = supplierRepository.Delete(id);

            if (result == 0)
            {
                return(Content(HttpStatusCode.NotFound, "Not Found"));
            }
            return(Ok());
        }
        public IHttpActionResult Delete(int Id)
        {
            var delete = supplierRepository.Delete(Id);

            if (delete == 0)
            {
                return(BadRequest("Data Tidak Ditemukan"));
            }
            return(Ok("Berhasil Delete"));
        }
Exemple #18
0
        public IHttpActionResult Delete(int id)
        {
            var DeleteSupplier = supplierRepository.Delete(id);

            if (DeleteSupplier == 0)
            {
                return(NotFound());
            }
            return(Ok("data has been inputted"));
        }
Exemple #19
0
        public IHttpActionResult Delete(int id)
        {
            var result = supplierRepository.Delete(id);

            if (result == 0)
            {
                return(Content(HttpStatusCode.NotFound, "Data Tidak Ditemukan"));
            }
            return(Ok("Berhasil Delete"));
        }
 public int Delete(int id)
 {
     if (string.IsNullOrEmpty(id.ToString()))
     {
         return(0);
     }
     else
     {
         return(_supplierRepository.Delete(id));
     }
 }
Exemple #21
0
        public ActionResult Delete(int id)
        {
            var item = SupplierRepository.Get(id);

            if (item != null)
            {
                SupplierRepository.Delete(item);
            }

            return(JsonSuccess());
        }
Exemple #22
0
 public IHttpActionResult Delete(int Id)
 {
     if (repository.Delete(Id) == 1)
     {
         return(Ok("Supplier data has been deleted"));
     }
     else
     {
         return(BadRequest("Supplier data cannot be deleted because ID cannot be found"));
     }
 }
Exemple #23
0
        public void DeleteSupplier()
        {
            Supplier toDelete = repo.GetUniq(p => p.SocietyName == "Nongfu");

            Assert.IsNotNull(repo.GetUniq(p => p.SocietyName == "Nongfu"));

            repo.Delete(toDelete);
            repo.Save();

            Assert.IsNull(repo.GetUniq(p => p.SocietyName == "Nongfu"));
        }
Exemple #24
0
        public IHttpActionResult Delete(int id)
        {
            var delete = sp.Delete(id);

            if (delete > 0)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Exemple #25
0
        public async Task <string> DeleteSupplier(int id)
        {
            string status = "";

            if (id > 0)
            {
                await supplierRepository.Delete(s => s.sup_id == id);

                status = "deleted";
            }
            return(status);
        }
 public IHttpActionResult Delete(Supplier s)
 {
     sr.Delete(s.SupplierID);
     try
     {
         return(Ok());
     }
     catch
     {
         //return Content(HttpStatusCode.BadRequest, "Failed to Delete Supplier");
         return(BadRequest("Failed to Delete Supplier"));
     }
 }
Exemple #27
0
        //delete data
        public bool Delete(int id)
        {
            var isDelete = false;

            isDelete = _sapplierRepository.Delete(id);
            if (isDelete)
            {
                return(true);
            }


            return(isDelete);
        }
Exemple #28
0
        public ActionResult Delete(int id)
        {
            Employee em  = (Employee)Session[CommonConstants.USER_SESSION];
            var      sup = _supRepo.GetById(id);

            sup.ModifyBy = em.id;
            var result = _supRepo.Delete(sup);

            if (result == 1)
            {
                return(Json(new { status = 1, message = "Xóa thành công" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = 1, message = "Xóa thất bại" }, JsonRequestBehavior.AllowGet));
        }
        public void SaveTest()
        {
            //Arrange
            Supplier supplier = new Supplier();

            supplier.SupplierCode    = "YYYY";
            supplier.CreatedDateTime = DateTime.Now;
            //Act
            var result = supplierService.Save(supplier);

            //Assert
            Assert.AreEqual("YYYY", result.SupplierCode);
            Assert.IsNotNull(context.Supplier.Where(x => x.SupplierCode == "YYYY").First());
            supplierRepository.Delete(result);
        }
Exemple #30
0
        public bool Delete(string SupplierCode)
        {
            var supplier = SupplierRepository.GetQueryable()
                           .FirstOrDefault(s => s.SupplierCode == SupplierCode);

            if (SupplierCode != null)
            {
                SupplierRepository.Delete(supplier);
                SupplierRepository.SaveChanges();
            }
            else
            {
                return(false);
            }
            return(true);
        }