Exemplo n.º 1
0
        private void SetDefaultData()
        {
            var animals = new Animals();

            var animal1 = new Animal("elephant");

            animal1.AddAttribute(new AnimalAttribute(AttributeType.Has, "a trunk"));
            animal1.AddAttribute(new AnimalAttribute(AttributeType.Has, "trumpets"));
            animal1.AddAttribute(new AnimalAttribute(AttributeType.Is, "grey"));
            animal1.AddAttribute(new AnimalAttribute(AttributeType.Is, "huge"));
            animals.Add(animal1);

            var animal2 = new Animal("lion");

            animal2.AddAttribute(new AnimalAttribute(AttributeType.Has, "a mane"));
            animal2.AddAttribute(new AnimalAttribute(AttributeType.Action, "roar"));
            animal2.AddAttribute(new AnimalAttribute(AttributeType.Has, "four legs"));
            animal2.AddAttribute(new AnimalAttribute(AttributeType.Is, "yellow"));
            animal2.AddAttribute(new AnimalAttribute(AttributeType.Is, "big"));
            animals.Add(animal2);

            var animal3 = new Animal("dog");

            animal3.AddAttribute(new AnimalAttribute(AttributeType.Action, "bark"));
            animal3.AddAttribute(new AnimalAttribute(AttributeType.Has, "four legs"));
            animal3.AddAttribute(new AnimalAttribute(AttributeType.Has, "hair"));
            animal3.AddAttribute(new AnimalAttribute(AttributeType.Is, "mammal"));
            animals.Add(animal3);

            var animal4 = new Animal("bird");

            animal4.AddAttribute(new AnimalAttribute(AttributeType.Action, "fly"));
            animal4.AddAttribute(new AnimalAttribute(AttributeType.Has, "wings"));
            animal4.AddAttribute(new AnimalAttribute(AttributeType.Has, "feathers"));
            animal4.AddAttribute(new AnimalAttribute(AttributeType.Is, "small"));
            animals.Add(animal4);

            var animal5 = new Animal("butterfly");

            animal5.AddAttribute(new AnimalAttribute(AttributeType.Action, "fly"));
            animal5.AddAttribute(new AnimalAttribute(AttributeType.Has, "wings"));
            animal5.AddAttribute(new AnimalAttribute(AttributeType.Has, "six legs"));
            animal5.AddAttribute(new AnimalAttribute(AttributeType.Is, "an insect"));
            animals.Add(animal5);

            _animalService.SaveAnimals(animals);

            _animals = _animalService.GetAnimals();
            ConsoleWrite($"Done. Animal data successfully saved to '{AnimalFile}'. Data has been refreshed.");
        }
Exemplo n.º 2
0
 public IndexModel(ILogger <IndexModel> logger, IAnimalService animalService)
 {
     _logger        = logger;
     _animalService = animalService;
     Animals        = _animalService.GetAnimals();
     ListOfAnimals  = new SelectList(_animalService.GetAnimalTypeNames());
 }
Exemplo n.º 3
0
        public IActionResult Get([FromQuery] AnimalQueryFilter filter)
        {
            var animals    = _service.GetAnimals(filter);
            var animalsDto = _mapper.Map <IEnumerable <Animal>, IEnumerable <AnimalResponseDto> >(animals);
            var response   = new ApiResponse <IEnumerable <AnimalResponseDto> >(animalsDto);

            return(Ok(response));
        }
Exemplo n.º 4
0
        public IActionResult Get()
        {
            var animals    = _service.GetAnimals();
            var animalsDto = _mapper.Map <IEnumerable <Animal>,
                                          IEnumerable <AnimalResponseDto> >(animals);
            var response = new ApiResponse <IEnumerable <AnimalResponseDto> >(animalsDto);

            return(Ok(response));
        }
Exemplo n.º 5
0
        public IActionResult Index()
        {
            var model = new DashboardDto
            {
                Habitats  = _habitatService.GetHabitats().Count(),
                Animals   = _animalService.GetAnimals().Count(),
                Employees = _employeeService.GetEmployees().Count()
            };

            return(View(model));
        }
Exemplo n.º 6
0
        public IActionResult AnimalPagedList([FromQuery] AnimalFilter filter)
        {
            try
            {
                var result = new PagingResultViewModel <AnimalListViewModel>();

                var pagingAnimals = _animalService.GetAnimals(filter.Page.Value, filter.PageSize.Value, filter.AnimalStatus, filter.Search, filter.IsActive);

                if (pagingAnimals.Elements.Any())
                {
                    var animalsListViewModel = pagingAnimals.Elements.Select(animal => new AnimalListViewModel()
                    {
                        Id          = animal.Id,
                        Name        = animal.Name,
                        Age         = animal.Age,
                        AnimalType  = animal.AnimalType.GetDescription(),
                        Behavior    = animal.Behavior,
                        Breed       = animal.Breed,
                        Status      = animal.Status,
                        AdopterName = animal.Adopter?.Name,
                        PictureUrl  = animal.PictureUrl
                    });

                    result = new PagingResultViewModel <AnimalListViewModel>(filter.Page.Value, filter.PageSize.Value)
                    {
                        Elements      = animalsListViewModel,
                        ElementsCount = pagingAnimals.ElementsCount
                    };
                }
                else
                {
                    return(RequestResponse(HttpStatusCode.NotFound, "hipets/api/v1/animals", result: "No content"));
                }

                return(IsAValidOperation()
                    ? RequestResponse(HttpStatusCode.OK, result: result)
                    : RequestResponse(HttpStatusCode.NotFound, "hipets/api/v1/animals", isError: true));
            }
            catch (Exception ex)
            {
                var error = JsonConvert.SerializeObject(ex);
                _logger.LogError(error);

                return(RequestResponse(HttpStatusCode.BadRequest, isError: true, result: "Ocorreu um erro ao listar os animais"));
            }
        }
Exemplo n.º 7
0
        public IActionResult Get([FromQuery] AnimalQueryFilter filter)
        {
            var animals    = _service.GetAnimals(filter);
            var animalsDto = _mapper.Map <IEnumerable <Animal>, IEnumerable <AnimalResponseDto> >(animals);
            var meta       = new Metadata
            {
                CurrentPage    = animals.CurrentPage,
                HasNextPage    = animals.HasNextPage,
                HasPreviusPage = animals.HasPreviusPage,
                PageSize       = animals.PageSize,
                TotalCount     = animals.TotalCount,
                TotalPage      = animals.TotalPages
            };

            var response = new ApiResponse <IEnumerable <AnimalResponseDto> >(animalsDto, meta);

            return(Ok(response));
        }
Exemplo n.º 8
0
 public async Task OnGetAsync()
 {
     Animals = await _animalservice.GetAnimals();
 }
        public IActionResult GetAll()
        {
            var animals = _animalService.GetAnimals();

            return(Ok(animals));
        }
Exemplo n.º 10
0
 public IEnumerable <Animal> GetAnimals()
 {
     return(animalService.GetAnimals());
 }
Exemplo n.º 11
0
 public IActionResult GetAll()
 {
     return(Ok(_animalService.GetAnimals()));
     // return Ok(new string[] { "value1", "value2" });
 }
Exemplo n.º 12
0
 public List <Animal> Get() => _animalService.GetAnimals();
Exemplo n.º 13
0
 public IActionResult Index()
 {
     return(View(_animalService.GetAnimals()));
 }