示例#1
0
        public ParishDTO GetParish(int parishId)
        {
            try
            {
                //Requires.NotNegative("parishId", parishId);

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

                // get
                R_Parish t = Repository.GetParish(parishId);

                ParishDTO dto = new ParishDTO(t);

                log.Debug(ParishDTO.FormatParishDTO(dto));

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

                throw;
            }
        }
示例#2
0
        public int AddParish(ParishDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(ParishDTO.FormatParishDTO(dto));

                R_Parish t = ParishDTO.ConvertDTOtoEntity(dto);

                // add
                id           = Repository.AddParish(t);
                dto.ParishId = id;

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

                throw;
            }

            return(id);
        }
示例#3
0
        public IEnumerable <R_Parish> GetParishListAdvancedSearch(
            int?countyId
            , int?districtId
            , int?countryId
            , string name
            , string code
            , double?latitude
            , double?longitude
            , bool?active
            )
        {
            IEnumerable <R_Parish> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Parish")
                      .Where("IsDeleted = 0"
                             + (countyId != null ? " and CountyId like '%" + countyId + "%'" : "")
                             + (districtId != null ? " and DistrictId like '%" + districtId + "%'" : "")
                             + (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_Parish.Query(sql);

            return(results);
        }
示例#4
0
        public void UpdateParish(R_Parish t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "ParishId");

            t.Update();
        }
示例#5
0
        // example data

        public static R_Parish SampleParish(int id = 1)
        {
            R_Parish parish = new R_Parish();

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

            return(parish);
        }
示例#6
0
        public void GetParishs_Success_Test()
        {
            // Arrange
            R_Parish parish = SampleParish(1);

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

            list.Add(parish);

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

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

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            var       resultList = parishService.GetParishs();
            ParishDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ParishId);
        }
示例#7
0
        public R_Parish GetParish(int parishId)
        {
            //Requires.NotNegative("parishId", parishId);

            R_Parish t = R_Parish.SingleOrDefault(parishId);

            return(t);
        }
示例#8
0
        public IEnumerable <R_Parish> GetParishs()
        {
            IEnumerable <R_Parish> results = null;

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

            ;

            results = R_Parish.Query(sql);

            return(results);
        }
示例#9
0
 public ParishDTO(R_Parish parish)
 {
     ParishId   = parish.ParishId;
     CountyId   = parish.CountyId;
     DistrictId = parish.DistrictId;
     CountryId  = parish.CountryId;
     Name       = parish.Name;
     Code       = parish.Code;
     Latitude   = parish.Latitude;
     Longitude  = parish.Longitude;
     Active     = parish.Active;
     IsDeleted  = parish.IsDeleted;
     CreateBy   = parish.CreateBy;
     CreateOn   = parish.CreateOn;
     UpdateBy   = parish.UpdateBy;
     UpdateOn   = parish.UpdateOn;
 }
示例#10
0
        public IList <R_Parish> GetParishs(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Parish> results = null;

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

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

            return(results);
        }
示例#11
0
        public static R_Parish ConvertDTOtoEntity(ParishDTO dto)
        {
            R_Parish parish = new R_Parish();

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

            return(parish);
        }
示例#12
0
        public void DeleteParish(ParishDTO dto)
        {
            try
            {
                log.Debug(ParishDTO.FormatParishDTO(dto));

                R_Parish t = ParishDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
示例#13
0
        public void GetParish_Success_Test()
        {
            // Arrange
            int      id     = 1;
            R_Parish parish = SampleParish(id);

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

            mock.Setup(s => s.GetParish(Moq.It.IsAny <int>())).Returns(parish);

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            ParishDTO result = parishService.GetParish(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ParishId);
        }
示例#14
0
        public void UpdateParish(ParishDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "ParishId");

                log.Debug(ParishDTO.FormatParishDTO(dto));

                R_Parish t = ParishDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateParish(t);

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

                throw;
            }
        }
示例#15
0
 public void DeleteParish(R_Parish t)
 {
     t.IsDeleted = true;
     t.Update();
 }
示例#16
0
        public int AddParish(R_Parish t)
        {
            int id = (int)t.Insert();

            return(id);
        }