public CountryDTO GetCountry(int countryId) { try { //Requires.NotNegative("countryId", countryId); log.Debug("countryId: " + countryId + " "); // get R_Country t = Repository.GetCountry(countryId); CountryDTO dto = new CountryDTO(t); log.Debug(CountryDTO.FormatCountryDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public int AddCountry(CountryDTO dto) { int id = 0; try { log.Debug(CountryDTO.FormatCountryDTO(dto)); R_Country t = CountryDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddCountry(t); dto.CountryId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public void GetCountrys_Success_Test() { // Arrange R_Country country = SampleCountry(1); IList <R_Country> list = new List <R_Country>(); list.Add(country); // create mock for repository var mock = new Mock <ICountryRepository>(); mock.Setup(s => s.GetCountrys()).Returns(list); // service CountryService countryService = new CountryService(); CountryService.Repository = mock.Object; // Act var resultList = countryService.GetCountrys(); CountryDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.CountryId); }
// example data public static R_Country SampleCountry(int id = 1) { R_Country country = new R_Country(); // int country.CountryId = id; // string country.Name = "NameTestValue"; // string country.EnglishName = "EnglishNameTestValue"; // string country.IsoCode = "IsoCodeTestValue"; // string country.CapitalCity = "CapitalCityTestValue"; // double? country.Latitude = 1; // double? country.Longitude = 1; // double? country.PhonePrefix = 1; // bool country.Active = false; // bool country.IsDeleted = false; // int? country.CreateBy = 1; // System.DateTime? country.CreateOn = new System.DateTime(); // int? country.UpdateBy = 1; // System.DateTime? country.UpdateOn = new System.DateTime(); return(country); }
public void UpdateCountry(R_Country t) { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "CountryId"); t.Update(); }
public IEnumerable <R_Country> GetCountryListAdvancedSearch( string name , string englishName , string isoCode , string capitalCity , double?latitude , double?longitude , double?phonePrefix , bool?active ) { IEnumerable <R_Country> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Country") .Where("IsDeleted = 0" + (name != null ? " and Name like '%" + name + "%'" : "") + (englishName != null ? " and EnglishName like '%" + englishName + "%'" : "") + (isoCode != null ? " and IsoCode like '%" + isoCode + "%'" : "") + (capitalCity != null ? " and CapitalCity like '%" + capitalCity + "%'" : "") + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "") + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "") + (phonePrefix != null ? " and PhonePrefix like '%" + phonePrefix + "%'" : "") + (active != null ? " and Active = " + (active == true ? "1" : "0") : "") ) ; results = R_Country.Query(sql); return(results); }
public R_Country GetCountry(int countryId) { //Requires.NotNegative("countryId", countryId); R_Country t = R_Country.SingleOrDefault(countryId); return(t); }
public IEnumerable <R_Country> GetCountrys() { IEnumerable <R_Country> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Country") .Where("IsDeleted = 0") ; results = R_Country.Query(sql); return(results); }
public CountryDTO(R_Country country) { CountryId = country.CountryId; Name = country.Name; EnglishName = country.EnglishName; IsoCode = country.IsoCode; CapitalCity = country.CapitalCity; Latitude = country.Latitude; Longitude = country.Longitude; PhonePrefix = country.PhonePrefix; Active = country.Active; IsDeleted = country.IsDeleted; CreateBy = country.CreateBy; CreateOn = country.CreateOn; UpdateBy = country.UpdateBy; UpdateOn = country.UpdateOn; }
public IList <R_Country> GetCountrys(string searchTerm, int pageIndex, int pageSize) { IList <R_Country> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Country") .Where("IsDeleted = 0") .Where( "Name like '%" + searchTerm + "%'" + " or " + "EnglishName like '%" + searchTerm + "%'" + " or " + "IsoCode like '%" + searchTerm + "%'" + " or " + "CapitalCity like '%" + searchTerm + "%'" ) ; results = R_Country.Fetch(pageIndex, pageSize, sql); return(results); }
public static R_Country ConvertDTOtoEntity(CountryDTO dto) { R_Country country = new R_Country(); country.CountryId = dto.CountryId; country.Name = dto.Name; country.EnglishName = dto.EnglishName; country.IsoCode = dto.IsoCode; country.CapitalCity = dto.CapitalCity; country.Latitude = dto.Latitude; country.Longitude = dto.Longitude; country.PhonePrefix = dto.PhonePrefix; country.Active = dto.Active; country.IsDeleted = dto.IsDeleted; country.CreateBy = dto.CreateBy; country.CreateOn = dto.CreateOn; country.UpdateBy = dto.UpdateBy; country.UpdateOn = dto.UpdateOn; return(country); }
public void DeleteCountry(CountryDTO dto) { try { log.Debug(CountryDTO.FormatCountryDTO(dto)); R_Country t = CountryDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteCountry(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void GetCountry_Success_Test() { // Arrange int id = 1; R_Country country = SampleCountry(id); // create mock for repository var mock = new Mock <ICountryRepository>(); mock.Setup(s => s.GetCountry(Moq.It.IsAny <int>())).Returns(country); // service CountryService countryService = new CountryService(); CountryService.Repository = mock.Object; // Act CountryDTO result = countryService.GetCountry(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.CountryId); }
public void UpdateCountry(CountryDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "CountryId"); log.Debug(CountryDTO.FormatCountryDTO(dto)); R_Country t = CountryDTO.ConvertDTOtoEntity(dto); // update Repository.UpdateCountry(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void DeleteCountry(R_Country t) { t.IsDeleted = true; t.Update(); }
public int AddCountry(R_Country t) { int id = (int)t.Insert(); return(id); }