Пример #1
0
        public ProjectDTO GetProject(int projectId)
        {
            try
            {
                //Requires.NotNegative("projectId", projectId);

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

                // get
                R_Project t = Repository.GetProject(projectId);

                ProjectDTO dto = new ProjectDTO(t);

                log.Debug(ProjectDTO.FormatProjectDTO(dto));

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

                throw;
            }
        }
Пример #2
0
        public void GetProjects_Success_Test()
        {
            // Arrange
            R_Project project = SampleProject(1);

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

            list.Add(project);

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

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

            // service
            ProjectService projectService = new ProjectService();

            ProjectService.Repository = mock.Object;

            // Act
            var        resultList = projectService.GetProjects();
            ProjectDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ProjectId);
        }
Пример #3
0
        public int AddProject(ProjectDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(ProjectDTO.FormatProjectDTO(dto));

                R_Project t = ProjectDTO.ConvertDTOtoEntity(dto);

                // add
                id            = Repository.AddProject(t);
                dto.ProjectId = id;

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

                throw;
            }

            return(id);
        }
Пример #4
0
        public void UpdateProject(R_Project t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "ProjectId");

            t.Update();
        }
Пример #5
0
        public R_Project GetProject(int projectId)
        {
            //Requires.NotNegative("projectId", projectId);

            R_Project t = R_Project.SingleOrDefault(projectId);

            return(t);
        }
Пример #6
0
 public R_Project GetModel(int id)
 {
     using (var db = CreateClient())
     {
         R_Project res = db.Queryable <R_Project>()
                         .Where(p => p.Id == id).FirstOrDefault();
         return(res);
     }
 }
Пример #7
0
        public IEnumerable <R_Project> GetProjects()
        {
            IEnumerable <R_Project> results = null;

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

            ;

            results = R_Project.Query(sql);

            return(results);
        }
Пример #8
0
        public bool Create(R_Project req)
        {
            using (var db = CreateClient())
            {
                bool result = true;
                var  model  = db.Insert(req);

                if (model != null)
                {
                    result = false;
                }

                return(result);
            }
        }
Пример #9
0
 public ProjectDTO(R_Project project)
 {
     ProjectId      = project.ProjectId;
     NucleoId       = project.NucleoId;
     Name           = project.Name;
     Description    = project.Description;
     DeadlineCall   = project.DeadlineCall;
     Budget         = project.Budget;
     Funding        = project.Funding;
     StartDate      = project.StartDate;
     EndDate        = project.EndDate;
     AreaOfInterest = project.AreaOfInterest;
     Active         = project.Active;
     IsDeleted      = project.IsDeleted;
     CreateBy       = project.CreateBy;
     CreateOn       = project.CreateOn;
     UpdateBy       = project.UpdateBy;
     UpdateOn       = project.UpdateOn;
 }
Пример #10
0
        public IList <R_Project> GetProjects(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Project> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Project")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                + " or " + "Description like '%" + searchTerm + "%'"
                + " or " + "DeadlineCall like '%" + searchTerm + "%'"
                + " or " + "Funding like '%" + searchTerm + "%'"
                + " or " + "AreaOfInterest like '%" + searchTerm + "%'"
                )
            ;

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

            return(results);
        }
Пример #11
0
        public IEnumerable <R_Project> GetProjectListAdvancedSearch(
            int?nucleoId
            , string name
            , string description
            , string deadlineCall
            , double?budget
            , string funding
            , System.DateTime?startDateFrom
            , System.DateTime?startDateTo
            , System.DateTime?endDateFrom
            , System.DateTime?endDateTo
            , string areaOfInterest
            , bool?active
            )
        {
            IEnumerable <R_Project> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Project")
                      .Where("IsDeleted = 0"
                             + (nucleoId != null ? " and NucleoId like '%" + nucleoId + "%'" : "")
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (description != null ? " and Description like '%" + description + "%'" : "")
                             + (deadlineCall != null ? " and DeadlineCall like '%" + deadlineCall + "%'" : "")
                             + (budget != null ? " and Budget like '%" + budget + "%'" : "")
                             + (funding != null ? " and Funding like '%" + funding + "%'" : "")
                             + (startDateFrom != null ? " and StartDate >= '" + startDateFrom.Value.ToShortDateString() + "'" : "")
                             + (startDateTo != null ? " and StartDate <= '" + startDateTo.Value.ToShortDateString() + "'" : "")
                             + (endDateFrom != null ? " and EndDate >= '" + endDateFrom.Value.ToShortDateString() + "'" : "")
                             + (endDateTo != null ? " and EndDate <= '" + endDateTo.Value.ToShortDateString() + "'" : "")
                             + (areaOfInterest != null ? " and AreaOfInterest like '%" + areaOfInterest + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Project.Query(sql);

            return(results);
        }
Пример #12
0
        public void DeleteProject(ProjectDTO dto)
        {
            try
            {
                log.Debug(ProjectDTO.FormatProjectDTO(dto));

                R_Project t = ProjectDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Пример #13
0
        // example data

        public static R_Project SampleProject(int id = 1)
        {
            R_Project project = new R_Project();

            // int
            project.ProjectId = id;
            // int?
            project.NucleoId = 1;
            // string
            project.Name = "NameTestValue";
            // string
            project.Description = "DescriptionTestValue";
            // string
            project.DeadlineCall = "DeadlineCallTestValue";
            // double?
            project.Budget = 1;
            // string
            project.Funding = "FundingTestValue";
            // System.DateTime?
            project.StartDate = new System.DateTime();
            // System.DateTime?
            project.EndDate = new System.DateTime();
            // string
            project.AreaOfInterest = "AreaOfInterestTestValue";
            // bool
            project.Active = false;
            // bool
            project.IsDeleted = false;
            // int?
            project.CreateBy = 1;
            // System.DateTime?
            project.CreateOn = new System.DateTime();
            // int?
            project.UpdateBy = 1;
            // System.DateTime?
            project.UpdateOn = new System.DateTime();

            return(project);
        }
Пример #14
0
        public void GetProject_Success_Test()
        {
            // Arrange
            int       id      = 1;
            R_Project project = SampleProject(id);

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

            mock.Setup(s => s.GetProject(Moq.It.IsAny <int>())).Returns(project);

            // service
            ProjectService projectService = new ProjectService();

            ProjectService.Repository = mock.Object;

            // Act
            ProjectDTO result = projectService.GetProject(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ProjectId);
        }
Пример #15
0
        public static R_Project ConvertDTOtoEntity(ProjectDTO dto)
        {
            R_Project project = new R_Project();

            project.ProjectId      = dto.ProjectId;
            project.NucleoId       = dto.NucleoId;
            project.Name           = dto.Name;
            project.Description    = dto.Description;
            project.DeadlineCall   = dto.DeadlineCall;
            project.Budget         = dto.Budget;
            project.Funding        = dto.Funding;
            project.StartDate      = dto.StartDate;
            project.EndDate        = dto.EndDate;
            project.AreaOfInterest = dto.AreaOfInterest;
            project.Active         = dto.Active;
            project.IsDeleted      = dto.IsDeleted;
            project.CreateBy       = dto.CreateBy;
            project.CreateOn       = dto.CreateOn;
            project.UpdateBy       = dto.UpdateBy;
            project.UpdateOn       = dto.UpdateOn;

            return(project);
        }
Пример #16
0
        public void UpdateProject(ProjectDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "ProjectId");

                log.Debug(ProjectDTO.FormatProjectDTO(dto));

                R_Project t = ProjectDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateProject(t);

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

                throw;
            }
        }
Пример #17
0
 public void DeleteProject(R_Project t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Пример #18
0
        public int AddProject(R_Project t)
        {
            int id = (int)t.Insert();

            return(id);
        }
Пример #19
0
 public bool Create(R_Project req)
 {
     return(_cyxmRepository.Create(req));
 }