public FishStockModel(SpeciesModel specie, double quantity, double latestPrice, int id) { Id = id; Specie = specie; Quantity = quantity; LatestPrice = latestPrice; }
public static async Task <SpeciesModel> GetSingleSpecies(string id) { string url = $"https://swapi.co/api/species/{ id }/"; SpeciesModel cached = speciesCache.Where(p => p.Id == id).FirstOrDefault(); if (cached != null) { return(cached); } using (HttpResponseMessage response = await apiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { // if response was successful // read the content of the response asynchronously // map it over to the person model SpeciesModel output = await response.Content.ReadAsAsync <SpeciesModel>(); output.Id = id; return(output); } else { throw new Exception(response.ReasonPhrase); } } }
private void SetModels() { NewBreed = new BreedModel(); NewSpecies = new SpeciesModel(); NewCoatType = new CoatTypeModel(); NewFurColor = new FurColorModel(); }
public void AddSpecies(int CategoryId, string CommonName, string LatinName) { var context = new WildlifeContext(); var category = context.Categories.Where((e) => e.Id == CategoryId).First(); var species = new SpeciesModel(); category.SpeciesList.Add(species); species.CommonName = CommonName; species.LatinName = LatinName; context.SaveChanges(); }
public ActionResult <bool> Create(SpeciesModel input) { try { return(Ok(_repository.Create(input))); } catch (Exception ex) { _logger.LogError($"Error: Controller exception on Create(T input)"); return(StatusCode((int)HttpStatusCode.InternalServerError, new { Error = ex.Message })); } }
public ActionResult <bool> Update(int id, SpeciesModel entity) { try { return(Ok(_repository.Update(id, entity))); } catch (Exception ex) { _logger.LogError($"Error: Controller exception on Update(int id, T entity)"); return(StatusCode((int)HttpStatusCode.InternalServerError, new { Error = ex.Message })); } }
public void DeleteSpecies() { MessageBoxResult result = MessageBox.Show("Opravdu chcete vymazat zvolený druh?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { SpeciesModel.MarkAsDeleted(SelectedSpecies.Id); LoadSpecies(); } }
public IHttpActionResult GetById(int id) { SpeciesModel speciesModel = _service.GetById <SpeciesModel>(id); if (speciesModel != null) { return(Json(speciesModel)); } else { return(BadRequest()); } }
public bool Post(SpeciesModel speciesModel) { try { SpeciesRepository speciesRepository = new SpeciesRepository(); Species species = new Species(); species.Identifier = speciesModel.Identifier; speciesRepository.Insert(species); return(true); } catch { return(false); } }
public IHttpActionResult Get(int speciesId) { var species = _speciesService.GetSpecies(speciesId); if (species == null) { return(NotFound()); } var model = new SpeciesModel(); Mapper.Map(species, model); model.HasAssociations = _speciesService.HasAssociations(species); return(Ok(model)); }
public static async Task <List <SpeciesModel> > DisplayAllSpecies(List <SpeciesModel> species) { string lookUpAnother = ""; do { try { foreach (SpeciesModel s in species) { string id = s.Url.Split('/')[5]; s.Id = id; Console.WriteLine($"{s.Id} {s.Name}"); } Console.Write("\nPlease enter an ID number: "); string idText = Console.ReadLine(); SpeciesModel sp = await GetSingleSpecies(idText); List <PersonModel> person = await CharacterController.GetStarWarsCharacters(sp.People); List <FilModel> film = await FilmController.GetStarWarsFilms(sp.Films); PlanetModel planet = await PlanetController.GetSpeciesHomeworld(sp.Homeworld); Console.WriteLine("============================================================"); Console.WriteLine($"Name: {sp.Name} | Classification: {sp.Classification}"); Console.WriteLine($"Designation: {sp.Designation} | Average Height: {sp.AverageHeight}cm"); Console.WriteLine($"Skin Colors: {sp.SkinColors}"); Console.WriteLine($"Hair Colors: {sp.HairColors}"); Console.WriteLine($"Eye Colors: {sp.EyeColors}"); Console.WriteLine($"Average Lifespan: {sp.AverageLifespan} years"); Console.WriteLine($"Homeworld: {planet.Name} | Language: {sp.Language}"); Console.WriteLine($"People: {CharacterController.FormatPersonLine(person)}"); Console.WriteLine($"Films: {FilmController.FormatFilmLine(film)}"); Console.WriteLine("============================================================"); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } Console.Write("Do you want to look up another character (y/n)?"); lookUpAnother = Console.ReadLine(); } while (lookUpAnother == "y"); return(null); }
private async Task LoadData() { IsWorking = true; await Task.Delay(150); await Task.Run(() => { SexList = SexModel.ReturnSexes(); SpeciesList = SpeciesModel.ReturnSpecies(); BreedList = BreedModel.ReturnBreeds(null); CoatTypeList = CoatTypeModel.ReturnCoatTypes(); FurColorList = FurColorModel.ReturnFurColors(); }); IsWorking = false; }
public bool Delete(int id) { ICollection <SpeciesModel> species = ReadAll(); SpeciesModel model = species.FirstOrDefault(x => x.Id == id); if (model != default) { bool remove = species.Remove(model); if (remove) { File.WriteAllText(_path, JsonSerializer.Serialize(species)); return(true); } } return(false); }
private async Task <SpeciesModel> GetSpecies(Uri uri) { SpeciesModel specie = new SpeciesModel(); if (int.TryParse(uri.ToString().Split('/')[5], out int id)) { using HttpResponseMessage httpResponse = await _httpClient.GetAsync(uri); if (httpResponse.StatusCode == HttpStatusCode.OK && httpResponse.Content != null) { specie = await JsonSerializer.DeserializeAsync <SpeciesModel>(await httpResponse.Content.ReadAsStreamAsync()); specie.Id = id; } } return(specie); }
public bool Create(SpeciesModel entity) { if (entity == default) { return(false); } ICollection <SpeciesModel> species = ReadAll(); SpeciesModel model = species.FirstOrDefault(x => x.Id == entity.Id); if (model == default) { species.Add(entity); File.WriteAllText(_path, JsonSerializer.Serialize(species)); return(true); } return(false); }
private async Task <List <SpeciesModel> > GetAllSpecies(List <SpeciesModel> species, Result result) { if (result?.Species != default) { foreach (Uri uri in result.Species) { Thread.Sleep(2000); SpeciesModel specie = await GetSpecies(uri); if (specie != default) { species.Add(specie); } } } return(species); }
public bool Update(SpeciesModel speciesModel) { SpeciesRepository speciesRepository = new SpeciesRepository(); Species species = new Species(); try { species.Id = speciesModel.Id; species.Identifier = speciesModel.Identifier; speciesRepository.Update(species); return(true); } catch { return(false); } }
public IHttpActionResult Post([FromBody] SpeciesModel speciesModel) { if (speciesModel.Identifier != null) { if (_service.Post(speciesModel)) { return(Ok()); } else { return(BadRequest()); } } else { return(BadRequest()); } }
public SpeciesModel GetById(int id) { SpeciesRepository speciesRepository = new SpeciesRepository(); try { Species species = speciesRepository.GetById(id); SpeciesModel speciesModel = new SpeciesModel(); speciesModel.Id = species.Id; speciesModel.Identifier = species.Identifier; return(speciesModel); } catch { return(null); } }
public IHttpActionResult Update([FromBody] SpeciesModel speciesModel) { if (speciesModel != null || speciesModel.Identifier != null) { bool result = _service.Update(speciesModel); if (result) { return(Ok()); } else { return(BadRequest()); } } else { return(BadRequest()); } }
private async Task LoadData() { IsWorking = true; await Task.Delay(150); await Task.Run(() => { SexList = SexModel.ReturnSexes(); SpeciesList = SpeciesModel.ReturnSpecies(); BreedList = BreedModel.ReturnBreeds(Animal.SpeciesID); CrossBreedList = BreedModel.ReturnBreeds(Animal.SpeciesID); CoatTypeList = CoatTypeModel.ReturnCoatTypes(); FurColorList = FurColorModel.ReturnFurColors(); VetList = PersonModel.ReturnVets(); OwnerList = PersonModel.ReturnOwners(); NewOwnerList = PersonModel.ReturnOwners(); }); IsWorking = false; }
public IHttpActionResult Update([FromUri] int speciesId, [FromBody] SpeciesModel model) { var species = _speciesService.GetSpecies(model.Id); if (species == null) { return(NotFound()); } Mapper.Map(model, species); if (!_speciesService.IsSpeciesExists(species)) { _speciesService.UpdateSpecies(species); } else { model.SetError("Name", "Duplicate species name"); } return(Ok(model)); }
public static async Task <List <SpeciesModel> > GetStarWarsSpecies(string[] id) { string url = ""; List <SpeciesModel> model = new List <SpeciesModel>(); foreach (string apiLink in id) { apiLink.Split(','); url = $"{ apiLink }"; SpeciesModel cahced = speciesCache.Where(s => s.Id == apiLink).FirstOrDefault(); if (cahced != null) { model.Add(cahced); } else { using (HttpResponseMessage response = await apiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { SpeciesModel output = await response.Content.ReadAsAsync <SpeciesModel>(); output.Id = apiLink; model.Add(output); speciesCache.Add(output); } else { throw new Exception(response.ReasonPhrase); } } } } return(model); }
public bool Update(int id, SpeciesModel entity) { if (entity is null) { return(false); } ICollection <SpeciesModel> species = ReadAll(); SpeciesModel model = species.FirstOrDefault(x => x.Id == id); if (model != default) { bool remove = species.Remove(model); if (remove) { species.Add(entity); File.WriteAllText(_path, JsonSerializer.Serialize(species)); return(true); } } return(false); }
public List <SpeciesModel> Get() { SpeciesRepository speciesRepository = new SpeciesRepository(); try { List <Species> speciess = speciesRepository.Get(); List <SpeciesModel> speciesModels = new List <SpeciesModel>(); foreach (Species species in speciess) { SpeciesModel speciesModel = new SpeciesModel(); speciesModel.Id = species.Id; speciesModel.Identifier = species.Identifier; speciesModels.Add(speciesModel); } return(speciesModels); } catch { return(null); } }
public IHttpActionResult Create([FromBody] SpeciesModel model) { try { var species = new Species(); Mapper.Map(model, species); if (!_speciesService.IsSpeciesExists(species)) { _speciesService.CreateSpecies(species); model.Id = species.Id; } else { model.SetError("Name", "Duplicate species name"); } return(Ok(model)); } catch { return(InternalServerError()); } }
////Default request without search Term //public ActionResult ApiSearch() //{ // ViewBag.Message = ("SWAPI results"); // return View(); //} //request with search Term public async Task <ActionResult> ApiSearch(string searchTerm) { if (searchTerm != null && searchTerm.Length < 10) { List <PersonModel> people = new List <PersonModel>(); ResultModel res = await ResultProcessor.GetStarWarsRootinfo(searchTerm); for (int i = 0; i < res.Count; i++) { people.Add(res.results[i]); //Get and set species Name. string[] speciesUrl = res.results[i].Species; SpeciesModel speciesRes = await SpeciesSearch(speciesUrl[0]); people[i].SpeciesName = speciesRes.SpeciesName; //Get and set Movie titles. int movieCount = res.results[i].Movies.Length; string[] movieUrls = res.results[i].Movies; for (int x = 0; x < movieCount; x++) { string url = movieUrls[x]; MovieModel movieRes = await MovieSearch(url); people[i].FilmsStarredIn.Add(movieRes); } } return(View(people)); } else { return(View("index")); } }
public async void Restore() { if (Since == null || To == null || (Since > To)) { MessageBox.Show("Zvolte prosím platné datum."); } else { IsWorking = true; await Task.Delay(150); await Task.Run(() => { AdoptionModel.RestoreDeleted((DateTime)Since, (DateTime)To); AnimalModel.RestoreDeleted((DateTime)Since, (DateTime)To); BreedModel.RestoreDeleted((DateTime)Since, (DateTime)To); CoatTypeModel.RestoreDeleted((DateTime)Since, (DateTime)To); CostModel.RestoreDeleted((DateTime)Since, (DateTime)To); DeathModel.RestoreDeleted((DateTime)Since, (DateTime)To); DiaryModel.RestoreDeleted((DateTime)Since, (DateTime)To); DonationModel.RestoreDeleted((DateTime)Since, (DateTime)To); EscapeModel.RestoreDeleted((DateTime)Since, (DateTime)To); FurColorModel.RestoreDeleted((DateTime)Since, (DateTime)To); IncidentModel.RestoreDeleted((DateTime)Since, (DateTime)To); PersonModel.RestoreDeleted((DateTime)Since, (DateTime)To); MedicalRecordModel.RestoreDeleted((DateTime)Since, (DateTime)To); SpeciesModel.RestoreDeleted((DateTime)Since, (DateTime)To); StayModel.RestoreDeleted((DateTime)Since, (DateTime)To); WalkModel.RestoreDeleted((DateTime)Since, (DateTime)To); }); ComboBoxSettings(); IsWorking = false; MessageBox.Show("Záznamy od " + Since + " do " + To + " obnoveny."); } }
public void ClearNewSpecies() { NewSpecies = new SpeciesModel(); NotifyOfPropertyChange(() => NewSpeciesName); NotifyOfPropertyChange(() => NewSpeciesSelected); }
private void LoadSpecies() { SpeciesList = SpeciesModel.ReturnSpecies(); }