示例#1
0
        public IEnumerable <AllocatedTime> SearchAllocatedTimes(SearchAllocatedTimesRequest request)
        {
            IQueryable <AllocatedTime> userAllocatedTimes = _context.AllocatedTimes.Include(at => at.Project.User)
                                                            .Include(at => at.Project.Customer)
                                                            .Include(at => at.Invoice)
                                                            .Where(at => at.Project.User.Id == request.UserId);

            if (request.StartDate != null)
            {
                userAllocatedTimes = userAllocatedTimes.Where(at => at.StartDate > request.StartDate);
            }
            if (request.EndDate != null)
            {
                userAllocatedTimes = userAllocatedTimes.Where(at => at.EndDate < request.EndDate);
            }
            if (request.CustomerId != null)
            {
                userAllocatedTimes = userAllocatedTimes.Where(at => at.Project.Customer.Id == request.UserId);
            }
            if (request.Invoiced != null)
            {
                userAllocatedTimes = userAllocatedTimes.Where(at => (request.Invoiced.Value && at.Invoice != null) || (!request.Invoiced.Value && at.Invoice == null));
            }
            if (userAllocatedTimes == null)
            {
                throw new NotFoundException();
            }

            return(userAllocatedTimes);
        }
        public ActionResult SearchAllocatedTimes([FromRoute] int userId, DateTime?startDate, DateTime?endDate, int?customerId, bool?invoiced)
        {
            try
            {
                SearchAllocatedTimesRequest searchRequest = new SearchAllocatedTimesRequest();
                searchRequest.UserId     = userId;
                searchRequest.StartDate  = startDate;
                searchRequest.EndDate    = endDate;
                searchRequest.CustomerId = customerId;
                searchRequest.Invoiced   = invoiced;

                IEnumerable <AllocatedTime> allocatedTimes = _projectService.SearchAllocatedTimes(searchRequest).ToList();

                return(Ok(allocatedTimes.Select(at => new
                {
                    at.Id,
                    at.Description,
                    at.StartDate,
                    at.EndDate,
                    invoiced = at.Invoice != null,
                    project = new {
                        at.Project.Id,
                        at.Project.Name,
                        customer = new
                        {
                            at.Project.Customer.Id,
                            at.Project.Customer.Name
                        },
                        user = new
                        {
                            at.Project.User.Id,
                            at.Project.User.Name,
                            at.Project.User.Surname,
                        }
                    }
                })));
            }
            catch (NotFoundException nfex)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An Error Occurred");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public ActionResult <IEnumerable <AllocatedTime> > GetAllocatedTimesByProjectId([FromRoute] int userId)
        {
            try
            {
                SearchAllocatedTimesRequest searchRequest = new SearchAllocatedTimesRequest();
                searchRequest.UserId = userId;

                IEnumerable <AllocatedTime> allocatedTimes = _projectService.SearchAllocatedTimes(searchRequest);
                return(Ok(allocatedTimes));
            }
            catch (NotFoundException nfex)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An Error Occurred");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }