コード例 #1
0
        public IEnumerable <R_Nucleo> GetNucleoListAdvancedSearch(
            string name
            , string personResponsible
            , int?photo
            , int?addressId
            , System.DateTime?openingDateFrom
            , System.DateTime?openingDateTo
            , string primaryPhoneNumber
            , string primaryEmail
            , bool?active
            )
        {
            IEnumerable <R_Nucleo> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Nucleo")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (personResponsible != null ? " and PersonResponsible like '%" + personResponsible + "%'" : "")
                             + (photo != null ? " and Photo like '%" + photo + "%'" : "")
                             + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "")
                             + (openingDateFrom != null ? " and OpeningDate >= '" + openingDateFrom.Value.ToShortDateString() + "'" : "")
                             + (openingDateTo != null ? " and OpeningDate <= '" + openingDateTo.Value.ToShortDateString() + "'" : "")
                             + (primaryPhoneNumber != null ? " and PrimaryPhoneNumber like '%" + primaryPhoneNumber + "%'" : "")
                             + (primaryEmail != null ? " and PrimaryEmail like '%" + primaryEmail + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Nucleo.Query(sql);

            return(results);
        }
コード例 #2
0
        public void UpdateNucleo(R_Nucleo t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "NucleoId");

            t.Update();
        }
コード例 #3
0
        // example data

        public static R_Nucleo SampleNucleo(int id = 1)
        {
            R_Nucleo nucleo = new R_Nucleo();

            // int
            nucleo.NucleoId = id;
            // string
            nucleo.Name = "NameTestValue";
            // string
            nucleo.PersonResponsible = "PersonResponsibleTestValue";
            // int?
            nucleo.Photo = 1;
            // int?
            nucleo.AddressId = 1;
            // System.DateTime?
            nucleo.OpeningDate = new System.DateTime();
            // string
            nucleo.PrimaryPhoneNumber = "PrimaryPhoneNumberTestValue";
            // string
            nucleo.PrimaryEmail = "PrimaryEmailTestValue";
            // bool
            nucleo.Active = false;
            // bool
            nucleo.IsDeleted = false;
            // int?
            nucleo.CreateBy = 1;
            // System.DateTime?
            nucleo.CreateOn = new System.DateTime();
            // int?
            nucleo.UpdateBy = 1;
            // System.DateTime?
            nucleo.UpdateOn = new System.DateTime();

            return(nucleo);
        }
コード例 #4
0
        public NucleoDTO GetNucleo(int nucleoId)
        {
            try
            {
                //Requires.NotNegative("nucleoId", nucleoId);

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

                // get
                R_Nucleo t = Repository.GetNucleo(nucleoId);

                NucleoDTO dto = new NucleoDTO(t);

                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

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

                throw;
            }
        }
コード例 #5
0
        public void GetNucleos_Success_Test()
        {
            // Arrange
            R_Nucleo nucleo = SampleNucleo(1);

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

            list.Add(nucleo);

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

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

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            var       resultList = nucleoService.GetNucleos();
            NucleoDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
        }
コード例 #6
0
        public int AddNucleo(NucleoDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

                // add
                id           = Repository.AddNucleo(t);
                dto.NucleoId = id;

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

                throw;
            }

            return(id);
        }
コード例 #7
0
        public R_Nucleo GetNucleo(int nucleoId)
        {
            //Requires.NotNegative("nucleoId", nucleoId);

            R_Nucleo t = R_Nucleo.SingleOrDefault(nucleoId);

            return(t);
        }
コード例 #8
0
        public IEnumerable <R_Nucleo> GetNucleos()
        {
            IEnumerable <R_Nucleo> results = null;

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

            ;

            results = R_Nucleo.Query(sql);

            return(results);
        }
コード例 #9
0
 public NucleoDTO(R_Nucleo nucleo)
 {
     NucleoId           = nucleo.NucleoId;
     Name               = nucleo.Name;
     PersonResponsible  = nucleo.PersonResponsible;
     Photo              = nucleo.Photo;
     AddressId          = nucleo.AddressId;
     OpeningDate        = nucleo.OpeningDate;
     PrimaryPhoneNumber = nucleo.PrimaryPhoneNumber;
     PrimaryEmail       = nucleo.PrimaryEmail;
     Active             = nucleo.Active;
     IsDeleted          = nucleo.IsDeleted;
     CreateBy           = nucleo.CreateBy;
     CreateOn           = nucleo.CreateOn;
     UpdateBy           = nucleo.UpdateBy;
     UpdateOn           = nucleo.UpdateOn;
 }
コード例 #10
0
        public IList <R_Nucleo> GetNucleos(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Nucleo> results = null;

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

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

            return(results);
        }
コード例 #11
0
        public static R_Nucleo ConvertDTOtoEntity(NucleoDTO dto)
        {
            R_Nucleo nucleo = new R_Nucleo();

            nucleo.NucleoId           = dto.NucleoId;
            nucleo.Name               = dto.Name;
            nucleo.PersonResponsible  = dto.PersonResponsible;
            nucleo.Photo              = dto.Photo;
            nucleo.AddressId          = dto.AddressId;
            nucleo.OpeningDate        = dto.OpeningDate;
            nucleo.PrimaryPhoneNumber = dto.PrimaryPhoneNumber;
            nucleo.PrimaryEmail       = dto.PrimaryEmail;
            nucleo.Active             = dto.Active;
            nucleo.IsDeleted          = dto.IsDeleted;
            nucleo.CreateBy           = dto.CreateBy;
            nucleo.CreateOn           = dto.CreateOn;
            nucleo.UpdateBy           = dto.UpdateBy;
            nucleo.UpdateOn           = dto.UpdateOn;

            return(nucleo);
        }
コード例 #12
0
        public void DeleteNucleo(NucleoDTO dto)
        {
            try
            {
                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
コード例 #13
0
        public void GetNucleo_Success_Test()
        {
            // Arrange
            int      id     = 1;
            R_Nucleo nucleo = SampleNucleo(id);

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

            mock.Setup(s => s.GetNucleo(Moq.It.IsAny <int>())).Returns(nucleo);

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            NucleoDTO result = nucleoService.GetNucleo(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
        }
コード例 #14
0
        public void UpdateNucleo(NucleoDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "NucleoId");

                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateNucleo(t);

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

                throw;
            }
        }
コード例 #15
0
 public void DeleteNucleo(R_Nucleo t)
 {
     t.IsDeleted = true;
     t.Update();
 }
コード例 #16
0
        public int AddNucleo(R_Nucleo t)
        {
            int id = (int)t.Insert();

            return(id);
        }