Exemple #1
0
        public void UpdateTask(R_Task t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "TaskId");

            t.Update();
        }
Exemple #2
0
        public void GetTasks_Success_Test()
        {
            // Arrange
            R_Task task = SampleTask(1);

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

            list.Add(task);

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

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

            // service
            TaskService taskService = new TaskService();

            TaskService.Repository = mock.Object;

            // Act
            var     resultList = taskService.GetTasks();
            TaskDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TaskId);
        }
Exemple #3
0
        public TaskDTO GetTask(int taskId)
        {
            try
            {
                //Requires.NotNegative("taskId", taskId);

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

                // get
                R_Task t = Repository.GetTask(taskId);

                TaskDTO dto = new TaskDTO(t);

                log.Debug(TaskDTO.FormatTaskDTO(dto));

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

                throw;
            }
        }
Exemple #4
0
        public int AddTask(TaskDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(TaskDTO.FormatTaskDTO(dto));

                R_Task t = TaskDTO.ConvertDTOtoEntity(dto);

                // add
                id         = Repository.AddTask(t);
                dto.TaskId = id;

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

                throw;
            }

            return(id);
        }
Exemple #5
0
        public R_Task GetTask(int taskId)
        {
            //Requires.NotNegative("taskId", taskId);

            R_Task t = R_Task.SingleOrDefault(taskId);

            return(t);
        }
Exemple #6
0
        public IEnumerable <R_Task> GetTasks()
        {
            IEnumerable <R_Task> results = null;

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

            ;

            results = R_Task.Query(sql);

            return(results);
        }
Exemple #7
0
        public IList <R_Task> GetTasks(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Task> results = null;

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

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

            return(results);
        }
Exemple #8
0
        public IEnumerable <R_Task> GetTaskListAdvancedSearch(
            string name
            , int?taskTypeId
            , System.DateTime?taskDateFrom
            , System.DateTime?taskDateTo
            , int?weekDay
            , System.DateTime?startTimeFrom
            , System.DateTime?startTimeTo
            , System.DateTime?endTimeFrom
            , System.DateTime?endTimeTo
            , int?estimatedDuration
            , string description
            , bool?requiresCar
            , int?teamLeaderId
            , bool?active
            )
        {
            IEnumerable <R_Task> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Task")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (taskTypeId != null ? " and TaskTypeId like '%" + taskTypeId + "%'" : "")
                             + (taskDateFrom != null ? " and TaskDate >= '" + taskDateFrom.Value.ToShortDateString() + "'" : "")
                             + (taskDateTo != null ? " and TaskDate <= '" + taskDateTo.Value.ToShortDateString() + "'" : "")
                             + (weekDay != null ? " and WeekDay like '%" + weekDay + "%'" : "")
                             + (startTimeFrom != null ? " and StartTime >= '" + startTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (startTimeTo != null ? " and StartTime <= '" + startTimeTo.Value.ToShortDateString() + "'" : "")
                             + (endTimeFrom != null ? " and EndTime >= '" + endTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (endTimeTo != null ? " and EndTime <= '" + endTimeTo.Value.ToShortDateString() + "'" : "")
                             + (estimatedDuration != null ? " and EstimatedDuration like '%" + estimatedDuration + "%'" : "")
                             + (description != null ? " and Description like '%" + description + "%'" : "")
                             + (requiresCar != null ? " and RequiresCar like '%" + requiresCar + "%'" : "")
                             + (teamLeaderId != null ? " and TeamLeaderId like '%" + teamLeaderId + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Task.Query(sql);

            return(results);
        }
Exemple #9
0
 public TaskDTO(R_Task task)
 {
     TaskId            = task.TaskId;
     Name              = task.Name;
     TaskTypeId        = task.TaskTypeId;
     TaskDate          = task.TaskDate;
     WeekDay           = task.WeekDay;
     StartTime         = task.StartTime;
     EndTime           = task.EndTime;
     EstimatedDuration = task.EstimatedDuration;
     Description       = task.Description;
     RequiresCar       = task.RequiresCar;
     TeamLeaderId      = task.TeamLeaderId;
     Active            = task.Active;
     IsDeleted         = task.IsDeleted;
     CreateBy          = task.CreateBy;
     CreateOn          = task.CreateOn;
     UpdateBy          = task.UpdateBy;
     UpdateOn          = task.UpdateOn;
 }
Exemple #10
0
        // example data

        public static R_Task SampleTask(int id = 1)
        {
            R_Task task = new R_Task();

            // int
            task.TaskId = id;
            // string
            task.Name = "NameTestValue";
            // int?
            task.TaskTypeId = 1;
            // System.DateTime?
            task.TaskDate = new System.DateTime();
            // int?
            task.WeekDay = 1;
            // System.DateTime?
            task.StartTime = new System.DateTime();
            // System.DateTime?
            task.EndTime = new System.DateTime();
            // int?
            task.EstimatedDuration = 1;
            // string
            task.Description = "DescriptionTestValue";
            // bool?
            task.RequiresCar = false;
            // int?
            task.TeamLeaderId = 1;
            // bool
            task.Active = false;
            // bool
            task.IsDeleted = false;
            // int?
            task.CreateBy = 1;
            // System.DateTime?
            task.CreateOn = new System.DateTime();
            // int?
            task.UpdateBy = 1;
            // System.DateTime?
            task.UpdateOn = new System.DateTime();

            return(task);
        }
Exemple #11
0
        public void DeleteTask(TaskDTO dto)
        {
            try
            {
                log.Debug(TaskDTO.FormatTaskDTO(dto));

                R_Task t = TaskDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Exemple #12
0
        public void GetTask_Success_Test()
        {
            // Arrange
            int    id   = 1;
            R_Task task = SampleTask(id);

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

            mock.Setup(s => s.GetTask(Moq.It.IsAny <int>())).Returns(task);

            // service
            TaskService taskService = new TaskService();

            TaskService.Repository = mock.Object;

            // Act
            TaskDTO result = taskService.GetTask(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TaskId);
        }
Exemple #13
0
        public void UpdateTask(TaskDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "TaskId");

                log.Debug(TaskDTO.FormatTaskDTO(dto));

                R_Task t = TaskDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateTask(t);

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

                throw;
            }
        }
Exemple #14
0
        public static R_Task ConvertDTOtoEntity(TaskDTO dto)
        {
            R_Task task = new R_Task();

            task.TaskId            = dto.TaskId;
            task.Name              = dto.Name;
            task.TaskTypeId        = dto.TaskTypeId;
            task.TaskDate          = dto.TaskDate;
            task.WeekDay           = dto.WeekDay;
            task.StartTime         = dto.StartTime;
            task.EndTime           = dto.EndTime;
            task.EstimatedDuration = dto.EstimatedDuration;
            task.Description       = dto.Description;
            task.RequiresCar       = dto.RequiresCar;
            task.TeamLeaderId      = dto.TeamLeaderId;
            task.Active            = dto.Active;
            task.IsDeleted         = dto.IsDeleted;
            task.CreateBy          = dto.CreateBy;
            task.CreateOn          = dto.CreateOn;
            task.UpdateBy          = dto.UpdateBy;
            task.UpdateOn          = dto.UpdateOn;

            return(task);
        }
Exemple #15
0
 public void DeleteTask(R_Task t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Exemple #16
0
        public int AddTask(R_Task t)
        {
            int id = (int)t.Insert();

            return(id);
        }