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."); }
public IndexModel(ILogger <IndexModel> logger, IAnimalService animalService) { _logger = logger; _animalService = animalService; Animals = _animalService.GetAnimals(); ListOfAnimals = new SelectList(_animalService.GetAnimalTypeNames()); }
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)); }
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)); }
public IActionResult Index() { var model = new DashboardDto { Habitats = _habitatService.GetHabitats().Count(), Animals = _animalService.GetAnimals().Count(), Employees = _employeeService.GetEmployees().Count() }; return(View(model)); }
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")); } }
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)); }
public async Task OnGetAsync() { Animals = await _animalservice.GetAnimals(); }
public IActionResult GetAll() { var animals = _animalService.GetAnimals(); return(Ok(animals)); }
public IEnumerable <Animal> GetAnimals() { return(animalService.GetAnimals()); }
public IActionResult GetAll() { return(Ok(_animalService.GetAnimals())); // return Ok(new string[] { "value1", "value2" }); }
public List <Animal> Get() => _animalService.GetAnimals();
public IActionResult Index() { return(View(_animalService.GetAnimals())); }