public SupplierDTO GetSupplier(int supplierId) { try { //Requires.NotNegative("supplierId", supplierId); log.Debug("supplierId: " + supplierId + " "); // get R_Supplier t = Repository.GetSupplier(supplierId); SupplierDTO dto = new SupplierDTO(t); log.Debug(SupplierDTO.FormatSupplierDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public int AddSupplier(SupplierDTO dto) { int id = 0; try { log.Debug(SupplierDTO.FormatSupplierDTO(dto)); R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddSupplier(t); dto.SupplierId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public void GetSuppliers_Success_Test() { // Arrange R_Supplier supplier = SampleSupplier(1); IList <R_Supplier> list = new List <R_Supplier>(); list.Add(supplier); // create mock for repository var mock = new Mock <ISupplierRepository>(); mock.Setup(s => s.GetSuppliers()).Returns(list); // service SupplierService supplierService = new SupplierService(); SupplierService.Repository = mock.Object; // Act var resultList = supplierService.GetSuppliers(); SupplierDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.SupplierId); }
public void UpdateSupplier(R_Supplier t) { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "SupplierId"); t.Update(); }
public IEnumerable <R_Supplier> GetSupplierListAdvancedSearch( string name , int?supplierTypeId , string phone , string email , double?latitude , double?longitude , string description , string website , int?addressId ) { IEnumerable <R_Supplier> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Supplier") .Where("IsDeleted = 0" + (name != null ? " and Name like '%" + name + "%'" : "") + (supplierTypeId != null ? " and SupplierTypeId = " + supplierTypeId : "") + (phone != null ? " and Phone like '%" + phone + "%'" : "") + (email != null ? " and Email like '%" + email + "%'" : "") + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "") + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "") + (description != null ? " and Description like '%" + description + "%'" : "") + (website != null ? " and Website like '%" + website + "%'" : "") + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "") ) ; results = R_Supplier.Query(sql); return(results); }
public R_Supplier GetSupplier(int supplierId) { //Requires.NotNegative("supplierId", supplierId); R_Supplier t = R_Supplier.SingleOrDefault(supplierId); return(t); }
public IEnumerable <R_Supplier> GetSuppliers() { IEnumerable <R_Supplier> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Supplier") .Where("IsDeleted = 0") ; results = R_Supplier.Query(sql); return(results); }
public SupplierDTO(R_Supplier supplier) { SupplierId = supplier.SupplierId; Name = supplier.Name; SupplierTypeId = supplier.SupplierTypeId; Phone = supplier.Phone; Email = supplier.Email; Latitude = supplier.Latitude; Longitude = supplier.Longitude; Description = supplier.Description; Website = supplier.Website; AddressId = supplier.AddressId; IsDeleted = supplier.IsDeleted; CreateBy = supplier.CreateBy; CreateOn = supplier.CreateOn; UpdateBy = supplier.UpdateBy; UpdateOn = supplier.UpdateOn; }
public IList <R_Supplier> GetSuppliers(string searchTerm, int pageIndex, int pageSize) { IList <R_Supplier> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Supplier") .Where("IsDeleted = 0") .Where( "Name like '%" + searchTerm + "%'" + " or " + "Phone like '%" + searchTerm + "%'" + " or " + "Email like '%" + searchTerm + "%'" + " or " + "Description like '%" + searchTerm + "%'" + " or " + "Website like '%" + searchTerm + "%'" ) ; results = R_Supplier.Fetch(pageIndex, pageSize, sql); return(results); }
public void DeleteSupplier(SupplierDTO dto) { try { log.Debug(SupplierDTO.FormatSupplierDTO(dto)); R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteSupplier(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public static R_Supplier ConvertDTOtoEntity(SupplierDTO dto) { R_Supplier supplier = new R_Supplier(); supplier.SupplierId = dto.SupplierId; supplier.Name = dto.Name; supplier.SupplierTypeId = dto.SupplierTypeId; supplier.Phone = dto.Phone; supplier.Email = dto.Email; supplier.Latitude = dto.Latitude; supplier.Longitude = dto.Longitude; supplier.Description = dto.Description; supplier.Website = dto.Website; supplier.AddressId = dto.AddressId; supplier.IsDeleted = dto.IsDeleted; supplier.CreateBy = dto.CreateBy; supplier.CreateOn = dto.CreateOn; supplier.UpdateBy = dto.UpdateBy; supplier.UpdateOn = dto.UpdateOn; return(supplier); }
public void GetSupplier_Success_Test() { // Arrange int id = 1; R_Supplier supplier = SampleSupplier(id); // create mock for repository var mock = new Mock <ISupplierRepository>(); mock.Setup(s => s.GetSupplier(Moq.It.IsAny <int>())).Returns(supplier); // service SupplierService supplierService = new SupplierService(); SupplierService.Repository = mock.Object; // Act SupplierDTO result = supplierService.GetSupplier(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.SupplierId); }
// example data public static R_Supplier SampleSupplier(int id = 1) { R_Supplier supplier = new R_Supplier(); // int supplier.SupplierId = id; // string supplier.Name = "NameTestValue"; // int supplier.SupplierTypeId = 1; // string supplier.Phone = "PhoneTestValue"; // string supplier.Email = "EmailTestValue"; // double? supplier.Latitude = 1; // double? supplier.Longitude = 1; // string supplier.Description = "DescriptionTestValue"; // string supplier.Website = "WebsiteTestValue"; // int? supplier.AddressId = 1; // bool supplier.IsDeleted = false; // int? supplier.CreateBy = 1; // System.DateTime? supplier.CreateOn = new System.DateTime(); // int? supplier.UpdateBy = 1; // System.DateTime? supplier.UpdateOn = new System.DateTime(); return(supplier); }
public void UpdateSupplier(SupplierDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "SupplierId"); log.Debug(SupplierDTO.FormatSupplierDTO(dto)); R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto); // update Repository.UpdateSupplier(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void DeleteSupplier(R_Supplier t) { t.IsDeleted = true; t.Update(); }
public int AddSupplier(R_Supplier t) { int id = (int)t.Insert(); return(id); }