Beispiel #1
0
        private ParishDTO Create(ParishViewModel viewModel)
        {
            try
            {
                log.Debug(ParishViewModel.FormatParishViewModel(viewModel));

                ParishDTO parish = new ParishDTO();

                // copy values
                viewModel.UpdateDTO(parish, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                parish.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                parish.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_parishService.AddParish - " + ParishDTO.FormatParishDTO(parish));

                int id = _parishService.AddParish(parish);

                parish.ParishId = id;

                log.Debug("result: 'success', id: " + id);

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

                throw;
            }
        }
Beispiel #2
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;
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public static ParishDTO SampleParishDTO(int id = 1)
        {
            ParishDTO parish = new ParishDTO();

            // 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);
        }
Beispiel #5
0
        public void GetParishListAdvancedSearch_Success_Test()
        {
            // Arrange
            int?   countyId   = null;
            int?   districtId = null;
            int?   countryId  = null;
            string name       = null;
            string code       = null;
            double?latitude   = null;
            double?longitude  = null;
            bool?  active     = null;

            //int pageIndex = 0;
            int pageSize = 10;

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

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleParish(i));
            }

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

            mock.Setup(s => s.GetParishListAdvancedSearch(
                           Moq.It.IsAny <int?>()      // countyId
                           , Moq.It.IsAny <int?>()    // districtId
                           , Moq.It.IsAny <int?>()    // countryId
                           , Moq.It.IsAny <string>()  // name
                           , Moq.It.IsAny <string>()  // code
                           , Moq.It.IsAny <double?>() // latitude
                           , Moq.It.IsAny <double?>() // longitude
                           , Moq.It.IsAny <bool?>()   // active
                           )).Returns(list);

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            var resultList = parishService.GetParishListAdvancedSearch(
                countyId
                , districtId
                , countryId
                , name
                , code
                , latitude
                , longitude
                , active
                );

            ParishDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ParishId);
        }
Beispiel #6
0
        public void GetParishsPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

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

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleParish(i));
            }

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

            mock.Setup(s => s.GetParishs(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list);

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            var       resultList = parishService.GetParishs(searchTerm, pageIndex, pageSize);
            ParishDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ParishId);
            Assert.AreEqual(10, resultList.Count);
        }
Beispiel #7
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);
        }
Beispiel #8
0
 public ParishViewModel(ParishDTO t)
 {
     ParishId   = t.ParishId;
     CountyId   = t.CountyId;
     DistrictId = t.DistrictId;
     CountryId  = t.CountryId;
     Name       = t.Name;
     Code       = t.Code;
     Latitude   = t.Latitude;
     Longitude  = t.Longitude;
     Active     = t.Active;
     IsDeleted  = t.IsDeleted;
     CreateBy   = t.CreateBy;
     CreateOn   = t.CreateOn;
     UpdateBy   = t.UpdateBy;
     UpdateOn   = t.UpdateOn;
 }
Beispiel #9
0
        public ParishDTO UpdateDTO(ParishDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.ParishId   = this.ParishId;
                dto.CountyId   = this.CountyId;
                dto.DistrictId = this.DistrictId;
                dto.CountryId  = this.CountryId;
                dto.Name       = this.Name;
                dto.Code       = this.Code;
                dto.Latitude   = this.Latitude;
                dto.Longitude  = this.Longitude;
                dto.Active     = this.Active;
                dto.IsDeleted  = this.IsDeleted;

                dto.UpdateBy = updateBy;
                dto.UpdateOn = System.DateTime.UtcNow;
            }

            return(dto);
        }
Beispiel #10
0
        public void UpdateParish_Success_Test()
        {
            // Arrange
            ParishDTO dto = SampleParishDTO(1);

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

            mock.Setup(s => s.UpdateParish(Moq.It.IsAny <R_Parish>())).Verifiable();

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            parishService.UpdateParish(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
Beispiel #11
0
        private ParishDTO Update(ParishViewModel viewModel)
        {
            try
            {
                log.Debug(ParishViewModel.FormatParishViewModel(viewModel));

                // get
                log.Debug("_parishService.GetParish - parishId: " + viewModel.ParishId + " ");

                var existingParish = _parishService.GetParish(viewModel.ParishId);

                log.Debug("_parishService.GetParish - " + ParishDTO.FormatParishDTO(existingParish));

                if (existingParish != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingParish, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_parishService.UpdateParish - " + ParishDTO.FormatParishDTO(existingParish));

                    _parishService.UpdateParish(existingParish);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingParish: null, ParishId: " + viewModel.ParishId);
                }

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

                throw;
            }
        }
Beispiel #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;
            }
        }
Beispiel #13
0
        public void AddParish_Success_Test()
        {
            // Arrange
            ParishDTO dto = SampleParishDTO(1);

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

            mock.Setup(s => s.AddParish(Moq.It.IsAny <R_Parish>())).Returns(1);

            // service
            ParishService parishService = new ParishService();

            ParishService.Repository = mock.Object;

            // Act
            int id = parishService.AddParish(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.ParishId);
        }
Beispiel #14
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);
        }
Beispiel #15
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;
            }
        }