예제 #1
0
파일: JobDM.cs 프로젝트: bubriks/Phaethon
        public List <Job> ReadAll(JobQueryFilter jobQueryFilter)
        {
            if (jobQueryFilter.CustomerName == null)
            {
                jobQueryFilter.CustomerName = "";
            }
            if (jobQueryFilter.JobName == null)
            {
                jobQueryFilter.JobName = "";
            }
            if (jobQueryFilter.Description == null)
            {
                jobQueryFilter.Description = "";
            }
            if (jobQueryFilter.NumOfRecords <= 0)
            {
                jobQueryFilter.NumOfRecords = 10;
            }
            if (jobQueryFilter.From == jobQueryFilter.To && jobQueryFilter.From == new DateTime())
            {
                jobQueryFilter.From = _jobDa.GetEarliestEntry();
                jobQueryFilter.To   = _jobDa.GetLatestEntry() ?? DateTime.Now;
            }

            return(_jobDa.ReadAll(jobQueryFilter));
        }
예제 #2
0
        public Result <PagedList <Job> > GetAll(JobQueryFilter filter)
        {
            IEnumerable <Job> jobs;
            PagedList <Job>   pagedJobs = null;

            try
            {
                jobs = _unitOfWork.JobRepository.GetFullJobs();
                if (jobs != null)
                {
                    if (filter.Recents)
                    {
                        jobs = jobs.OrderByDescending(x => x.Date);
                    }
                    jobs = JobDataFilter.FilterJobs(jobs, filter);
                }

                if (jobs != null)
                {
                    filter.PageNumber = filter.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filter.PageNumber;
                    filter.PageSize   = filter.PageSize == 0 ? _paginationOptions.DefaultPageSize : filter.PageSize;

                    pagedJobs = PagedList <Job> .Create(jobs,
                                                        filter.PageNumber, filter.PageSize);
                }
            }
            catch (Exception ex)
            {
                return(Result <PagedList <Job> > .Error(new[] { ex.Message }));
            }
            var result = Result <PagedList <Job> > .Success(pagedJobs);

            return(result);
        }
예제 #3
0
        public async Task ReadJob_ReadAllFullFilter_ListOfJobs()
        {
            //Setup
            InitializeData();
            JobDa _jobDa = new JobDa();

            _jobDa.InsertOrUpdate(_job);
            _job.ID = 0;
            _jobDa.InsertOrUpdate(_job);
            JobQueryFilter jobQueryFilter = new JobQueryFilter
            {
                NumOfRecords = 10,
                DateOption   = 1,
                From         = DateTime.Today,
                To           = DateTime.Now.AddDays(1),
                JobName      = "Repair",
                CustomerName = "Test",
                Description  = "Test",
                JobStatus    = 0,
                JobId        = 0,
            };

            //Act
            var result = await _client.PostAsJsonAsync("Job/ReadAll", jobQueryFilter);

            string json = await result.Content.ReadAsStringAsync();

            List <Job> jobs = JsonConvert.DeserializeObject <List <Job> >(json);

            //Assert
            Assert.IsTrue(result.IsSuccessStatusCode);
            Assert.IsTrue(jobs.Count >= 2, $"Job Count: {jobs.Count}");
        }
예제 #4
0
        public static IEnumerable <Job> FilterJobs(IEnumerable <Job> jobs, JobQueryFilter jobQueryFilter)
        {
            if (!string.IsNullOrEmpty(jobQueryFilter.Search) && jobs != null)
            {
                jobs = FilterBySearch(jobs, jobQueryFilter.Search);
            }

            if (!string.IsNullOrEmpty(jobQueryFilter.Category) && jobs != null)
            {
                jobs = FilterByCategory(jobs, jobQueryFilter.Category);
            }

            if (!string.IsNullOrEmpty(jobQueryFilter.Company) && jobs != null)
            {
                jobs = FilterByCompany(jobs, jobQueryFilter.Company);
            }

            if (!string.IsNullOrEmpty(jobQueryFilter.Title) && jobs != null)
            {
                jobs = FilterByTitle(jobs, jobQueryFilter.Title);
            }

            if (!string.IsNullOrEmpty(jobQueryFilter.TypeSchedule) && jobs != null)
            {
                jobs = FilterByTypeSchedule(jobs, jobQueryFilter.TypeSchedule);
            }

            if (jobQueryFilter.Date != null && jobs != null)
            {
                jobs = FilterByDate(jobs, jobQueryFilter.Date);
            }

            return(jobs);
        }
예제 #5
0
        public async Task <string> GetJobsAjax(string jobName, string customerName, string description, int dateOption, string from, string to, int numOfRecords = 10, int jobId = 0, int jobStatus = 0)
        {
            DateTime fromDateTime = DateTime.Now, toDateTime = DateTime.Now;

            if (!from.IsNullOrWhiteSpace())
            {
                DateTime.TryParseExact(from, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out fromDateTime);
            }
            if (!to.IsNullOrWhiteSpace())
            {
                DateTime.TryParseExact(to, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out toDateTime);
            }

            JobQueryFilter jobFilter = new JobQueryFilter
            {
                NumOfRecords = numOfRecords,
                CustomerName = customerName,
                JobId        = jobId,
                JobStatus    = jobStatus,
                Description  = description,
                DateOption   = dateOption,
                From         = fromDateTime,
                To           = toDateTime
            };

            jobFilter.JobName = jobName;
            var response = await _client.PostAsJsonAsync("ReadAll", jobFilter);

            return(await response.Content.ReadAsStringAsync());
        }
예제 #6
0
        public IActionResult GetJobs([FromQuery] JobQueryFilter filter)
        {
            ApiResponse <IEnumerable <JobReadDto> > response;
            var resultJob = _JobService.GetAll(filter);

            if (resultJob.Status == ResultStatus.Error)
            {
                response = new ApiPagedResponse <IEnumerable <JobReadDto> >(Array.Empty <JobReadDto>())
                {
                    Title   = nameof(HttpStatusCode.InternalServerError),
                    Errors  = resultJob.Errors,
                    Satatus = (int)HttpStatusCode.InternalServerError
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, response));
            }
            var jobs = resultJob.Value;
            var meta = _mapper.Map <Metadata>(jobs);

            meta.NextPageUrl     = _uriService.GetPaginationNextUrl(filter, Request, meta.HasNextPage);
            meta.PreviousPageUrl = _uriService.GetPaginationPreviousUrl(filter, Request, meta.HasPreviousPage);
            var jobsReadDto = _mapper.Map <IEnumerable <JobReadDto> >(jobs);

            response = new ApiPagedResponse <IEnumerable <JobReadDto> >(jobsReadDto)
            {
                Title   = nameof(HttpStatusCode.OK),
                Meta    = meta,
                Satatus = (int)HttpStatusCode.OK
            };
            return(Ok(response));
        }
예제 #7
0
 public async Task <HttpResponseMessage> ReadAll([FromBody] JobQueryFilter jobQueryFilter)
 {
     try
     {
         if (Request.Content == null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, _jobDm.ReadAll(new JobQueryFilter())));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, _jobDm.ReadAll(jobQueryFilter)));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
     }
 }
예제 #8
0
        public async Task <HttpResponseMessage> ReadAll()
        {
            try
            {
                if (Request.Content == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, _jobDm.ReadAll(new JobQueryFilter())));
                }
                var json = await Request.Content.ReadAsStringAsync();

                JobQueryFilter jobQueryFilter = JsonConvert.DeserializeObject <JobQueryFilter>(json);
                return(Request.CreateResponse(HttpStatusCode.OK, _jobDm.ReadAll(jobQueryFilter)));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }
        }
예제 #9
0
 public List <Job> ReadAll(JobQueryFilter jobQueryFilter)
 {
     jobQueryFilter.To = jobQueryFilter.To.AddDays(1);
     using (var db = new DatabaseContext())
     {
         return(db.Jobs
                .Include(x => x.Customer)
                .Include(x => x.Customer.Address)
                .Where(x => (jobQueryFilter.JobId == 0 || x.ID == jobQueryFilter.JobId) &&
                       x.JobName.Contains(jobQueryFilter.JobName) &&
                       (x.Customer.GivenName + x.Customer.FamilyName).Contains(jobQueryFilter.CustomerName) &&
                       x.Description.Contains(jobQueryFilter.Description) &&
                       (jobQueryFilter.JobStatus == 0 || (int)x.JobStatus == jobQueryFilter.JobStatus)
                       )
                .Where(x => (jobQueryFilter.DateOption == 0 && jobQueryFilter.From <= x.StartedTime && x.StartedTime < jobQueryFilter.To) ||
                       (jobQueryFilter.DateOption == 1 && jobQueryFilter.From <= x.FinishedTime && x.FinishedTime < jobQueryFilter.To))
                .Take(jobQueryFilter.NumOfRecords)
                .ToList());
     }
 }
예제 #10
0
        public async Task <string> GetJobs(int?numOfRecords, int?jobId, string jobName, int?jobStatus, string customerName, string description, string dateOption, string from, string to)
        {
            DateTime fromDateTime = DateTime.Now, toDateTime = DateTime.Now;
            int      dateOp = 0;

            if (!from.IsNullOrWhiteSpace())
            {
                DateTime.TryParseExact(from, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out fromDateTime);
            }
            if (!to.IsNullOrWhiteSpace())
            {
                DateTime.TryParseExact(to, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out toDateTime);
            }
            if (!dateOption.IsNullOrWhiteSpace())
            {
                Int32.TryParse(dateOption, out dateOp);
            }

            JobQueryFilter jobFilter = new JobQueryFilter {
                CustomerName = customerName, DateOption = dateOp, Description = description, From = fromDateTime, To = toDateTime
            };

            if (numOfRecords != null)
            {
                jobFilter.NumOfRecords = (int)numOfRecords;
            }
            if (jobId != null)
            {
                jobFilter.JobId = (int)jobId;
            }
            if (jobStatus != null)
            {
                jobFilter.JobStatus = (int)jobStatus;
            }
            jobFilter.JobName = jobName;

            var response = await _client.PostAsJsonAsync("ReadAll", jobFilter);

            return(await response.Content.ReadAsStringAsync());
        }