public void GetVolunteers_Success_Test() { // Arrange R_Volunteer volunteer = SampleVolunteer(1); IList <R_Volunteer> list = new List <R_Volunteer>(); list.Add(volunteer); // create mock for repository var mock = new Mock <IVolunteerRepository>(); mock.Setup(s => s.GetVolunteers()).Returns(list); // service VolunteerService volunteerService = new VolunteerService(); VolunteerService.Repository = mock.Object; // Act var resultList = volunteerService.GetVolunteers(); VolunteerDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.VolunteerId); }
public IList <R_Volunteer> GetVolunteers(string searchTerm, int pageIndex, int pageSize) { IList <R_Volunteer> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Volunteer") .Where("IsDeleted = 0") .Where( "Name like '%" + searchTerm + "%'" + " or " + "Occupation like '%" + searchTerm + "%'" + " or " + "Employer like '%" + searchTerm + "%'" + " or " + "Phone like '%" + searchTerm + "%'" + " or " + "Email like '%" + searchTerm + "%'" + " or " + "IdentityCardNumber like '%" + searchTerm + "%'" + " or " + "FriendOrFamilyContact like '%" + searchTerm + "%'" + " or " + "VehicleMake like '%" + searchTerm + "%'" + " or " + "VehicleModel like '%" + searchTerm + "%'" ) ; results = R_Volunteer.Fetch(pageIndex, pageSize, sql); return(results); }
public void UpdateVolunteer(R_Volunteer t) { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "VolunteerId"); t.Update(); }
public VolunteerDTO GetVolunteer(int volunteerId) { try { //Requires.NotNegative("volunteerId", volunteerId); log.Debug("volunteerId: " + volunteerId + " "); // get R_Volunteer t = Repository.GetVolunteer(volunteerId); VolunteerDTO dto = new VolunteerDTO(t); log.Debug(VolunteerDTO.FormatVolunteerDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public int AddVolunteer(VolunteerDTO dto) { int id = 0; try { log.Debug(VolunteerDTO.FormatVolunteerDTO(dto)); R_Volunteer t = VolunteerDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddVolunteer(t); dto.VolunteerId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public VolunteerDTO(R_Volunteer volunteer) { VolunteerId = volunteer.VolunteerId; Name = volunteer.Name; Gender = volunteer.Gender; BirthDate = volunteer.BirthDate; Occupation = volunteer.Occupation; Employer = volunteer.Employer; Phone = volunteer.Phone; Email = volunteer.Email; IdentityCardNumber = volunteer.IdentityCardNumber; CountryId = volunteer.CountryId; FriendOrFamilyContact = volunteer.FriendOrFamilyContact; Photo = volunteer.Photo; AddressId = volunteer.AddressId; HasCar = volunteer.HasCar; HasDriverLicense = volunteer.HasDriverLicense; HasBike = volunteer.HasBike; VehicleMake = volunteer.VehicleMake; VehicleModel = volunteer.VehicleModel; Active = volunteer.Active; IsDeleted = volunteer.IsDeleted; CreateBy = volunteer.CreateBy; CreateOn = volunteer.CreateOn; UpdateBy = volunteer.UpdateBy; UpdateOn = volunteer.UpdateOn; }
public static R_Volunteer ConvertDTOtoEntity(VolunteerDTO dto) { R_Volunteer volunteer = new R_Volunteer(); volunteer.VolunteerId = dto.VolunteerId; volunteer.Name = dto.Name; volunteer.Gender = dto.Gender; volunteer.BirthDate = dto.BirthDate; volunteer.Occupation = dto.Occupation; volunteer.Employer = dto.Employer; volunteer.Phone = dto.Phone; volunteer.Email = dto.Email; volunteer.IdentityCardNumber = dto.IdentityCardNumber; volunteer.CountryId = dto.CountryId; volunteer.FriendOrFamilyContact = dto.FriendOrFamilyContact; volunteer.Photo = dto.Photo; volunteer.AddressId = dto.AddressId; volunteer.HasCar = dto.HasCar; volunteer.HasDriverLicense = dto.HasDriverLicense; volunteer.HasBike = dto.HasBike; volunteer.VehicleMake = dto.VehicleMake; volunteer.VehicleModel = dto.VehicleModel; volunteer.Active = dto.Active; volunteer.IsDeleted = dto.IsDeleted; volunteer.CreateBy = dto.CreateBy; volunteer.CreateOn = dto.CreateOn; volunteer.UpdateBy = dto.UpdateBy; volunteer.UpdateOn = dto.UpdateOn; return(volunteer); }
public R_Volunteer GetVolunteer(int volunteerId) { //Requires.NotNegative("volunteerId", volunteerId); R_Volunteer t = R_Volunteer.SingleOrDefault(volunteerId); return(t); }
// example data public static R_Volunteer SampleVolunteer(int id = 1) { R_Volunteer volunteer = new R_Volunteer(); // int volunteer.VolunteerId = id; // string volunteer.Name = "NameTestValue"; // int? volunteer.Gender = 1; // System.DateTime? volunteer.BirthDate = new System.DateTime(); // string volunteer.Occupation = "OccupationTestValue"; // string volunteer.Employer = "EmployerTestValue"; // string volunteer.Phone = "PhoneTestValue"; // string volunteer.Email = "EmailTestValue"; // string volunteer.IdentityCardNumber = "IdentityCardNumberTestValue"; // int? volunteer.CountryId = 1; // string volunteer.FriendOrFamilyContact = "FriendOrFamilyContactTestValue"; // int? volunteer.Photo = 1; // int? volunteer.AddressId = 1; // bool volunteer.HasCar = false; // bool volunteer.HasDriverLicense = false; // bool volunteer.HasBike = false; // string volunteer.VehicleMake = "VehicleMakeTestValue"; // string volunteer.VehicleModel = "VehicleModelTestValue"; // bool volunteer.Active = false; // bool volunteer.IsDeleted = false; // int? volunteer.CreateBy = 1; // System.DateTime? volunteer.CreateOn = new System.DateTime(); // int? volunteer.UpdateBy = 1; // System.DateTime? volunteer.UpdateOn = new System.DateTime(); return(volunteer); }
public IEnumerable <R_Volunteer> GetVolunteerListAdvancedSearch( string name , int?gender , System.DateTime?birthDateFrom , System.DateTime?birthDateTo , string occupation , string employer , string phone , string email , string identityCardNumber , int?countryId , string friendOrFamilyContact , int?photo , int?addressId , bool?hasCar , bool?hasDriverLicense , bool?hasBike , string vehicleMake , string vehicleModel , bool?active ) { IEnumerable <R_Volunteer> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Volunteer") .Where("IsDeleted = 0" + (name != null ? " and Name like '%" + name + "%'" : "") + (gender != null ? " and Gender like '%" + gender + "%'" : "") + (birthDateFrom != null ? " and BirthDate >= '" + birthDateFrom.Value.ToShortDateString() + "'" : "") + (birthDateTo != null ? " and BirthDate <= '" + birthDateTo.Value.ToShortDateString() + "'" : "") + (occupation != null ? " and Occupation like '%" + occupation + "%'" : "") + (employer != null ? " and Employer like '%" + employer + "%'" : "") + (phone != null ? " and Phone like '%" + phone + "%'" : "") + (email != null ? " and Email like '%" + email + "%'" : "") + (identityCardNumber != null ? " and IdentityCardNumber like '%" + identityCardNumber + "%'" : "") + (countryId != null ? " and CountryId like '%" + countryId + "%'" : "") + (friendOrFamilyContact != null ? " and FriendOrFamilyContact like '%" + friendOrFamilyContact + "%'" : "") + (photo != null ? " and Photo like '%" + photo + "%'" : "") + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "") + (hasCar != null ? " and HasCar = " + (hasCar == true ? "1" : "0") : "") + (hasDriverLicense != null ? " and HasDriverLicense = " + (hasDriverLicense == true ? "1" : "0") : "") + (hasBike != null ? " and HasBike = " + (hasBike == true ? "1" : "0") : "") + (vehicleMake != null ? " and VehicleMake like '%" + vehicleMake + "%'" : "") + (vehicleModel != null ? " and VehicleModel like '%" + vehicleModel + "%'" : "") + (active != null ? " and Active = " + (active == true ? "1" : "0") : "") ) ; results = R_Volunteer.Query(sql); return(results); }
public IEnumerable <R_Volunteer> GetVolunteers() { IEnumerable <R_Volunteer> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Volunteer") .Where("IsDeleted = 0") ; results = R_Volunteer.Query(sql); return(results); }
public void DeleteVolunteer(VolunteerDTO dto) { try { log.Debug(VolunteerDTO.FormatVolunteerDTO(dto)); R_Volunteer t = VolunteerDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteVolunteer(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void GetVolunteer_Success_Test() { // Arrange int id = 1; R_Volunteer volunteer = SampleVolunteer(id); // create mock for repository var mock = new Mock <IVolunteerRepository>(); mock.Setup(s => s.GetVolunteer(Moq.It.IsAny <int>())).Returns(volunteer); // service VolunteerService volunteerService = new VolunteerService(); VolunteerService.Repository = mock.Object; // Act VolunteerDTO result = volunteerService.GetVolunteer(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.VolunteerId); }
public void UpdateVolunteer(VolunteerDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "VolunteerId"); log.Debug(VolunteerDTO.FormatVolunteerDTO(dto)); R_Volunteer t = VolunteerDTO.ConvertDTOtoEntity(dto); // update Repository.UpdateVolunteer(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void DeleteVolunteer(R_Volunteer t) { t.IsDeleted = true; t.Update(); }
public int AddVolunteer(R_Volunteer t) { int id = (int)t.Insert(); return(id); }