Beispiel #1
0
        public void GetDistricts_Success_Test()
        {
            // Arrange
            R_District district = SampleDistrict(1);

            IList <R_District> list = new List <R_District>();

            list.Add(district);

            // create mock for repository
            var mock = new Mock <IDistrictRepository>();

            mock.Setup(s => s.GetDistricts()).Returns(list);

            // service
            DistrictService districtService = new DistrictService();

            DistrictService.Repository = mock.Object;

            // Act
            var         resultList = districtService.GetDistricts();
            DistrictDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.DistrictId);
        }
Beispiel #2
0
        // example data

        public static R_District SampleDistrict(int id = 1)
        {
            R_District district = new R_District();

            // int
            district.DistrictId = id;
            // int?
            district.CountryId = 1;
            // string
            district.Name = "NameTestValue";
            // string
            district.Code = "CodeTestValue";
            // double?
            district.Latitude = 1;
            // double?
            district.Longitude = 1;
            // bool
            district.Active = false;
            // bool
            district.IsDeleted = false;
            // int?
            district.CreateBy = 1;
            // System.DateTime?
            district.CreateOn = new System.DateTime();
            // int?
            district.UpdateBy = 1;
            // System.DateTime?
            district.UpdateOn = new System.DateTime();

            return(district);
        }
Beispiel #3
0
        public DistrictDTO GetDistrict(int districtId)
        {
            try
            {
                //Requires.NotNegative("districtId", districtId);

                log.Debug("districtId: " + districtId + " ");

                // get
                R_District t = Repository.GetDistrict(districtId);

                DistrictDTO dto = new DistrictDTO(t);

                log.Debug(DistrictDTO.FormatDistrictDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #4
0
        public IEnumerable <R_District> GetDistrictListAdvancedSearch(
            int?countryId
            , string name
            , string code
            , double?latitude
            , double?longitude
            , bool?active
            )
        {
            IEnumerable <R_District> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_District")
                      .Where("IsDeleted = 0"
                             + (countryId != null ? " and CountryId like '%" + countryId + "%'" : "")
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (code != null ? " and Code like '%" + code + "%'" : "")
                             + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "")
                             + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_District.Query(sql);

            return(results);
        }
Beispiel #5
0
        public void UpdateDistrict(R_District t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "DistrictId");

            t.Update();
        }
Beispiel #6
0
        public int AddDistrict(DistrictDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(DistrictDTO.FormatDistrictDTO(dto));

                R_District t = DistrictDTO.ConvertDTOtoEntity(dto);

                // add
                id             = Repository.AddDistrict(t);
                dto.DistrictId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
Beispiel #7
0
        public R_District GetDistrict(int districtId)
        {
            //Requires.NotNegative("districtId", districtId);

            R_District t = R_District.SingleOrDefault(districtId);

            return(t);
        }
Beispiel #8
0
        public IEnumerable <R_District> GetDistricts()
        {
            IEnumerable <R_District> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_District")
                      .Where("IsDeleted = 0")

            ;

            results = R_District.Query(sql);

            return(results);
        }
Beispiel #9
0
 public DistrictDTO(R_District district)
 {
     DistrictId = district.DistrictId;
     CountryId  = district.CountryId;
     Name       = district.Name;
     Code       = district.Code;
     Latitude   = district.Latitude;
     Longitude  = district.Longitude;
     Active     = district.Active;
     IsDeleted  = district.IsDeleted;
     CreateBy   = district.CreateBy;
     CreateOn   = district.CreateOn;
     UpdateBy   = district.UpdateBy;
     UpdateOn   = district.UpdateOn;
 }
Beispiel #10
0
        public IList <R_District> GetDistricts(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_District> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_District")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                + " or " + "Code like '%" + searchTerm + "%'"
                )
            ;

            results = R_District.Fetch(pageIndex, pageSize, sql);

            return(results);
        }
Beispiel #11
0
        public static R_District ConvertDTOtoEntity(DistrictDTO dto)
        {
            R_District district = new R_District();

            district.DistrictId = dto.DistrictId;
            district.CountryId  = dto.CountryId;
            district.Name       = dto.Name;
            district.Code       = dto.Code;
            district.Latitude   = dto.Latitude;
            district.Longitude  = dto.Longitude;
            district.Active     = dto.Active;
            district.IsDeleted  = dto.IsDeleted;
            district.CreateBy   = dto.CreateBy;
            district.CreateOn   = dto.CreateOn;
            district.UpdateBy   = dto.UpdateBy;
            district.UpdateOn   = dto.UpdateOn;

            return(district);
        }
Beispiel #12
0
        public void DeleteDistrict(DistrictDTO dto)
        {
            try
            {
                log.Debug(DistrictDTO.FormatDistrictDTO(dto));

                R_District t = DistrictDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteDistrict(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #13
0
        public void GetDistrict_Success_Test()
        {
            // Arrange
            int        id       = 1;
            R_District district = SampleDistrict(id);

            // create mock for repository
            var mock = new Mock <IDistrictRepository>();

            mock.Setup(s => s.GetDistrict(Moq.It.IsAny <int>())).Returns(district);

            // service
            DistrictService districtService = new DistrictService();

            DistrictService.Repository = mock.Object;

            // Act
            DistrictDTO result = districtService.GetDistrict(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.DistrictId);
        }
Beispiel #14
0
        public void UpdateDistrict(DistrictDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "DistrictId");

                log.Debug(DistrictDTO.FormatDistrictDTO(dto));

                R_District t = DistrictDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateDistrict(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #15
0
 public void DeleteDistrict(R_District t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Beispiel #16
0
        public int AddDistrict(R_District t)
        {
            int id = (int)t.Insert();

            return(id);
        }