public ActionResult <IEnumerable <FuelShow> > Get([FromQuery] FuelSearch query)
 {
     try
     {
         return(Ok(_getS.Execute(query)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(StatusCode(500));
     }
 }
Example #2
0
        public IEnumerable <FuelShow> Execute(FuelSearch request)
        {
            var fuels = Context.Fuels.AsQueryable();

            if (request.Type != null)
            {
                fuels.Where(f => f.Type.ToLower() == request.Type.ToLower());
            }

            return(fuels.Select(f => new FuelShow
            {
                Id = f.Id,
                Type = f.Type
            }));
        }
Example #3
0
        public PageResponse <GorivoDto> Execute(FuelSearch request)
        {
            var query        = Context.VrsteGoriva.AsQueryable().Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);
            var totalRecords = query.Count();
            var pagesCount   = (int)Math.Ceiling((double)totalRecords / request.PerPage);

            if (request != null)
            {
                if (request.Keyword != null)
                {
                    query = query.Where(g => g.Naziv
                                        .ToLower()
                                        .Contains(request.Keyword.ToLower()));
                }
                totalRecords = query.Count();
                var response = new PageResponse <GorivoDto>
                {
                    CurrentPage = request.PageNumber,
                    TotalCount  = totalRecords,
                    PagesCount  = pagesCount,
                    Data        = query.Select(g => new GorivoDto
                    {
                        Id           = g.Id,
                        NazivGoriva  = g.Naziv,
                        DateCreated  = g.DateCreated,
                        DateModified = g.DateModified
                    })
                };

                return(response);
            }
            else
            {
                return(new PageResponse <GorivoDto>
                {
                    CurrentPage = request.PageNumber,
                    TotalCount = totalRecords,
                    PagesCount = pagesCount,
                    Data = query.Select(g => new GorivoDto
                    {
                        Id = g.Id,
                        NazivGoriva = g.Naziv,
                        DateCreated = g.DateCreated,
                        DateModified = g.DateModified
                    })
                });
            }
        }
Example #4
0
 public IActionResult Get([FromQuery] FuelSearch search)
 {
     try
     {
         var goriva = _getFuelsCommand.Execute(search);
         return(Ok(goriva));
     }
     catch (EntityNotFoundException e)
     {
         if (e.Message == "Gorivo doesn't exist.")
         {
             return(NotFound(e.Message));
         }
         return(UnprocessableEntity(e.Message));
     }
 }