private void buttonConfirm_Click(object sender, EventArgs e) { Breeds breed = new Breeds(); Dog dog1 = new Dog(textBoxName.Text, dateTimePickerBirth.Value, breed); dog1.Salvar(query); }
public IEnumerable <RuminantTypeCohort> GetCohorts(RuminantInitialCohorts initials) { List <RuminantTypeCohort> list = new List <RuminantTypeCohort>(); int index = Breeds.IndexOf((initials.Parent as RuminantType).Breed); var cohorts = GetElementNames(Numbers).Skip(1); foreach (string cohort in cohorts) { double num = GetValue <double>(Numbers.Element(cohort), index); if (num <= 0) { continue; } list.Add(new RuminantTypeCohort(initials) { Name = cohort, Number = num, Age = GetValue <int>(Ages.Element(cohort), index), Weight = GetValue <double>(Weights.Element(cohort), index), Gender = cohort.Contains("F") ? 1 : 0, Suckling = cohort.Contains("Calf") ? true : false, Sire = cohort.Contains("ire") ? true : false }); } return(list.AsEnumerable()); }
public IEntity Generate(int breedId = -1) { var rand = new Random(); var breed = breedId == -1 ? Breeds.ElementAt(rand.Next(0, Breeds.Count)) : Breeds.FirstOrDefault(x => x.Id == breedId); byte gender = (byte)(rand.Next(100) >= 50 ? 1 : 0); var possibleHeads = Heads.Where(x => x.Breed == breed.Id && x.Gender == gender); var head = possibleHeads.ElementAt(rand.Next(0, possibleHeads.Count())); var look = EntityLookParser.Parse(gender == 0 ? breed.MaleLook : breed.FemaleLook); var entity = EntityFactory.Instance.CreateCharacter(); var entityLook = entity.Look(); var entityCharacter = entity.Character(); var entityStats = entity.Stats(); entityLook.Name = "ByPass" + Guid.NewGuid().ToString().Substring(0, 4); entityLook.BonesId = look.BonesId; entityLook.AddSkin(short.Parse(head.Skin)); entityLook.IndexedColors.AddRange(gender == 0 ? breed.MaleColors : breed.FemaleColors); entityLook.Scales.AddRange(look.Scales); entityCharacter.BreedId = breed.Id; entityCharacter.Gender = gender == 1; entityStats.Stats = new StatCollection(); return(entity); }
public async Task <ActionResult <Breeds> > PostBreeds(Breeds breeds) { _context.Breeds.Add(breeds); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBreeds", new { id = breeds.BreedId }, breeds)); }
private async Task ExecuteLoadBreedsCommand() { try { var result = await DoggoService.GetAllBreeds(); foreach (var keyValue in result.Message) { var subBreeds = new List <SubBreedModel>(); foreach (var subBreed in keyValue.Value) { subBreeds.Add(new SubBreedModel { Name = subBreed }); } Breeds.Add(new BreedModel { Name = keyValue.Key, SubBreeds = subBreeds }); } } catch (Exception ex) { } }
public void SetBreeds(Breeds breeds) { if (breeds != null) { Breeds = breeds; } }
public void SaveBreed() { try { if (BreedName != null) { using (ShelterDatabaseLINQDataContext db = new ShelterDatabaseLINQDataContext()) { Breeds breed = new Breeds { BreedName = BreedName, SpeciesID = SpeciesID, IsDeleted = null }; db.Breeds.InsertOnSubmit(breed); db.SubmitChanges(); ID = breed.Id; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public IActionResult CreateBreed([FromBody]Breeds breed) { try { if (breed == null || breed.Breed == string.Empty) { _logger.LogError("breed object sent from client is null."); return BadRequest("breed object is null"); } if (!ModelState.IsValid) { _logger.LogError("Invalid breed object sent from client."); return BadRequest("Invalid model object"); } _repository.Breeds.CreateBreed(breed); return CreatedAtRoute("BreedById", new { id = breed.Id }, breed); } catch (Exception ex) { _logger.LogError($"Something went wrong inside Create breed action: {ex.Message}"); return StatusCode(500, "Internal server error"); } }
//Hae yksi rotu public Breeds GetOneBreed(int key) { pethouseContext db = new pethouseContext(); Breeds breed = db.Find <Breeds>(key); return(breed); }
public async Task <IActionResult> PutBreeds(int id, Breeds breeds) { if (id != breeds.BreedId) { return(BadRequest()); } _context.Entry(breeds).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BreedsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult UpdateBreed(Guid id, [FromBody]Breeds breed) { try { if (breed == null) { _logger.LogError("breed object sent from client is null."); return BadRequest("breed object is null"); } if (!ModelState.IsValid) { _logger.LogError("Invalid breed object sent from client."); return BadRequest("Invalid model object"); } var dbbreed = _repository.Breeds.GetBreedsById(id); if (dbbreed == null) { _logger.LogError($"breed with id: {id}, hasn't been found in db."); return NotFound(); } _repository.Breeds.UpdateBreed(dbbreed, breed); return NoContent(); } catch (Exception ex) { _logger.LogError($"Something went wrong inside Update breed action: {ex.Message}"); return StatusCode(500, "Internal server error"); } }
public void UpdateBreed(Breeds dbbreed, Breeds breed) { var resultBreed = _breeds.First(b => b.Id == dbbreed.Id); resultBreed.Id = breed.Id; resultBreed.Breed = breed.Breed; resultBreed.GroupId = breed.GroupId; }
public void TestFilter() { Breeds breed1 = new Breeds(); Breeds.Kitty kitty1 = new Breeds.Kitty(); breed1.IsVisible(kitty1); }
public void RemoveAt(int index) { if (index < 0 || index >= Breeds.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } Breeds.RemoveAt(index); }
public bool Remove(IEnumerable <EGene> genes) { if (Contains(genes, out int i)) { Breeds.RemoveAt(i); return(true); } return(false); }
public bool TryAdd(Breed breed) { if (!AllowDuplicates && Contains(breed.ToString())) { return(false); } Breeds.Add(breed); return(true); }
public bool Remove(string genes) { if (Contains(genes, out int i)) { Breeds.RemoveAt(i); return(true); } return(false); }
private async Task GetBreedImagesAsync() { var list = Breeds.Select(x => x.id).ToList(); var temp = await SearchAllImages(string.Join(',', list)); if (temp.IsValid) { Dogs = temp.Results; } }
private void SetBreedBaseColors(Breeds breed) { var baseColors = BreedsUtility.GetBreedBaseColors(breed, CmbSex.SelectedIndex); RectColor1.Fill = new SolidColorBrush(baseColors[0]); RectColor2.Fill = new SolidColorBrush(baseColors[1]); RectColor3.Fill = new SolidColorBrush(baseColors[2]); RectColor4.Fill = new SolidColorBrush(baseColors[3]); RectColor5.Fill = new SolidColorBrush(baseColors[4]); }
public IEnumerable <ActivityFolder> GetManageBreeds(ActivityFolder folder) { List <ActivityFolder> folders = new List <ActivityFolder>(); foreach (string breed in PresentBreeds) { string name = breed.Replace(".", " "); int index = Breeds.IndexOf(breed); ActivityFolder manage = new ActivityFolder(folder) { Name = name }; manage.Add(new RuminantActivityWean(manage) { WeaningAge = GetValue <double>(RumSpecs.Element("Weaning_age"), index), WeaningWeight = GetValue <double>(RumSpecs.Element("Weaning_weight"), index), GrazeFoodStoreName = "NativePasture" }); string homemilk = GetValue <string>(RumSpecs.Element("Home_milk"), index); if (homemilk != "0") { manage.Add(new RuminantActivityMilking(manage) { ResourceTypeName = "HumanFoodStore." + name + "_Milk" }); } manage.Add(new RuminantActivityManage(manage) { MaximumBreedersKept = GetValue <int>(RumSpecs.Element("Max_breeders"), index), MaximumBreedingAge = GetValue <int>(RumSpecs.Element("Max_breeder_age"), index), MaximumBullAge = GetValue <int>(RumSpecs.Element("Max_Bull_age"), index), MaleSellingAge = GetValue <int>(RumSpecs.Element("Anim_sell_age"), index), MaleSellingWeight = GetValue <int>(RumSpecs.Element("Anim_sell_wt"), index), GrazeFoodStoreName = "GrazeFoodStore.NativePasture" }); manage.Add(new RuminantActivitySellDryBreeders(manage) { MinimumConceptionBeforeSell = 1, MonthsSinceBirth = GetValue <int>(RumSpecs.Element("Joining_age"), index), ProportionToRemove = GetValue <double>(RumSpecs.Element("Dry_breeder_cull_rate"), index) * 0.01 }); folders.Add(manage); } return(folders); }
private void SetParameters(RuminantType ruminant) { List <Tuple <string, string, double> > parameters = new List <Tuple <string, string, double> >() { new Tuple <string, string, double>("concep_rate_assym", "ConceptionRateAsymptote", 1), new Tuple <string, string, double>("concep_rate_coeff", "ConceptionRateCoefficient", 1), new Tuple <string, string, double>("concep_rate_incpt", "ConceptionRateIntercept", 1), new Tuple <string, string, double>("birth_SRW", "SRWBirth", 1), new Tuple <string, string, double>("cashmere_coeff", "CashmereCoefficient", 1), new Tuple <string, string, double>("Critical_cow_wt", "CriticalCowWeight", 0.01), new Tuple <string, string, double>("grwth_coeff1", "AgeGrowthRateCoefficient", 1), new Tuple <string, string, double>("grwth_coeff2", "SRWGrowthScalar", 1), new Tuple <string, string, double>("intake_coeff", "IntakeCoefficient", 1), new Tuple <string, string, double>("intake_incpt", "IntakeIntercept", 1), new Tuple <string, string, double>("IPI_coeff", "InterParturitionIntervalCoefficient", 1), new Tuple <string, string, double>("IPI_incpt", "InterParturitionIntervalIntercept", 1), new Tuple <string, string, double>("Joining_age", "MinimumAge1stMating", 1), new Tuple <string, string, double>("Joining_size", "MinimumSize1stMating", 0.01), new Tuple <string, string, double>("juvenile_mort_coeff", "JuvenileMortalityCoefficient", 1), new Tuple <string, string, double>("juvenile_mort_exp", "JuvenileMortalityExponent", 1), new Tuple <string, string, double>("juvenile_mort_max", "JuvenileMortalityMaximum", 0.01), new Tuple <string, string, double>("kg_coeff", "EGrowthEfficiencyCoefficient", 1), new Tuple <string, string, double>("kg_incpt", "EGrowthEfficiencyIntercept", 1), new Tuple <string, string, double>("kl_coeff", "ELactationEfficiencyCoefficient", 1), new Tuple <string, string, double>("kl_incpt", "ELactationEfficiencyIntercept", 1), new Tuple <string, string, double>("km_coeff", "EMaintEfficiencyCoefficient", 1), new Tuple <string, string, double>("km_incpt", "EMaintEfficiencyIntercept", 1), new Tuple <string, string, double>("kme", "Kme", 1), new Tuple <string, string, double>("Milk_Curve_nonsuck", "MilkCurveNonSuckling", 1), new Tuple <string, string, double>("Milk_Curve_suck", "MilkCurveSuckling", 1), new Tuple <string, string, double>("Milk_end", "MilkingDays", 30), new Tuple <string, string, double>("Milk_intake_coeff", "MilkIntakeCoefficient", 1), new Tuple <string, string, double>("Milk_intake_incpt", "MilkIntakeIntercept", 1), new Tuple <string, string, double>("Milk_max", "MilkPeakYield", 1), new Tuple <string, string, double>("Milk_offset_day", "MilkOffsetDay", 1), new Tuple <string, string, double>("Milk_Peak_day", "MilkPeakDay", 1), new Tuple <string, string, double>("Mortality_base", "MortalityBase", 0.01), new Tuple <string, string, double>("protein_coeff", "ProteinCoefficient", 1), new Tuple <string, string, double>("Rum_gest_int", "GestationLength", 1), new Tuple <string, string, double>("SRW", "SRWFemale", 1), new Tuple <string, string, double>("Twin_rate", "TwinRate", 1), new Tuple <string, string, double>("wool_coeff", "WoolCoefficient", 1) }; int index = Breeds.IndexOf(ruminant.Breed); foreach (var parameter in parameters) { double value = GetValue <double>(FindFirst(Source, parameter.Item1), index) * parameter.Item3; ruminant.GetType().GetProperty(parameter.Item2).SetValue(ruminant, value); } }
/// <summary> /// Método captura a lista Breeds da API TheCatAPI e armazena na base de dados /// juntamente com as imagens encontradas para cada Breeds /// </summary> /// <returns></returns> public async Task CapureAllBreedsWithImages() { // Captura uma lista de Breeds a partir da API TheCatAPI var breedsList = await theCatAPI.GetBreeds(); // Para cada Breeds encontrado, armazena na base de dados foreach (var breeds in breedsList) { // Verifica se Breeds já existe na base de dados, se não existir, armazena var breedsInDB = await breedsRepository.GetBreeds(breeds.Id); if (breedsInDB == null) { breedsInDB = new Breeds(breeds.Id, breeds.Name); breedsInDB.SetOrigin(breeds.Origin); breedsInDB.SetTemperament(breeds.Temperament); breedsInDB.SetDescription(breeds.Description); await breedsRepository.AddBreeds(breedsInDB); } // Econtra as imagens do registro Breeds atual, caso exista, armazena as imagens na base de dados var imagesList = await theCatAPI.GetImagesByBreeds(breeds.Id); if (imagesList != null && imagesList.Count > 0) { foreach (var image in imagesList) { // Verifica se Image existe. Se não, cria o objeto // A variável: imageExists, é para fazer o tratamento se Add ou Update // pois chamando este métodos, a tabela associativa será gravada, caso // a imagem não tenha existido anteriormente. var imageInDB = await imageUrlRepository.GetImageUrl(image.Id); var imageExists = imageInDB != null; if (!imageExists) { imageInDB = new ImageUrl(image.Id, image.Url); imageInDB.SetWidth(image.Width); imageInDB.SetHeight(image.Height); } imageInDB.SetBreeds(breedsInDB); if (!imageExists) { await imageUrlRepository.AddImageUrl(imageInDB); } else { await imageUrlRepository.UpdateImageUrl(imageInDB); } } } } }
public static async Task <Breeds> GetAllBreeds() { var query = "https://dog.ceo/api/breeds/list/all"; HttpClient client = new HttpClient(); var response = await client.GetStringAsync(query); Breeds data = null; if (response != null) { data = JsonConvert.DeserializeObject <Breeds>(response); } return(data); }
public static async Task <Breeds> GetDogByBreed(string breed) { var query = "https://dog.ceo/api/breed/" + breed + "/images/random"; HttpClient client = new HttpClient(); var response = await client.GetStringAsync(query); Breeds data = null; if (response != null) { data = JsonConvert.DeserializeObject <Breeds>(response); } return(data); }
public IEnumerable <SelectListItem> GetBreedsDropDown() { if (cultureInfo.Name == "pt-PT") { return(Breeds.OrderBy(b => b.Name).Select(b => new SelectListItem { Value = b.BreedId.ToString(), Text = b.NamePt })); } else { return(Breeds.OrderBy(b => b.Name).Select(b => new SelectListItem { Value = b.BreedId.ToString(), Text = b.Name })); } }
public void Get_WhenCalled_ReturnsAllItems1() { var res = new Breeds { Breed = "NewBreed", GroupId = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd91234"), Id = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd94321") }; // Act var okResult = _controller.CreateBreed(res); // Assert Assert.IsInstanceOf <CreatedAtRouteResult>(okResult); }
public void Get_WhenCalled_InvailedReturnsError() { var res = new Breeds { Breed = string.Empty, GroupId = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd91234"), Id = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd94321") }; // Act var okResult = _controller.CreateBreed(res); // Assert Assert.IsInstanceOf <BadRequestObjectResult>(okResult); }
public void Get_WhenCalled_ReturnsDeleteBreed11() { var deleteId = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd9c200"); var res = new Breeds { Breed = "NewBreed", GroupId = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd91234"), Id = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd94321") }; // Act var okResult = _controller.UpdateBreed(deleteId, res); // Assert Assert.IsInstanceOf <NoContentResult>(okResult); }
public NABSA(string path) { Source = XElement.Load(path); Name = Path.GetFileNameWithoutExtension(path); // General Data SingleParams = Source.Element("SingleParams"); // Land Data LandSpecs = Source.Element("LandSpecs"); // Labour Data Priority = FindByNameTag(Source, "Labour Number and Priority"); Supply = FindByNameTag(Source, "Labour Supply"); // Ruminant Data SuppAllocs = FindFirst(Source, "SuppAllocs"); SuppSpecs = FindFirst(Source, "SuppSpecs"); RumSpecs = FindFirst(Source, "RumSpecs"); Numbers = FindByNameTag(Source, "Startup ruminant numbers"); Ages = FindByNameTag(Source, "Startup ruminant ages"); Weights = FindByNameTag(Source, "Startup ruminant weights"); Prices = FindByNameTag(Source, "Ruminant prices"); Fodder = FindFirst(Source, "Fodder"); FodderSpecs = FindFirst(Source, "FodderSpecs"); // List of all possible breeds Breeds = SuppAllocs.Element("ColumnNames").Elements().Select(e => e.Value).ToList(); // Index of each breed var indices = from breed in Breeds select Breeds.IndexOf(breed); // Breeds that have a presence in the simulation PresentBreeds = from index in indices where ( // The total number of each breed from cohort in Numbers.Elements().Skip(1) select Convert.ToInt32(cohort.Elements().ToList()[index].Value) ).Sum() > 0 // Breeds with a non-zero number of ruminants present select Breeds.ElementAt(index); }
public async Task CapureAllBreedsWithImages() { var breedsList = await theCatAPI.GetBreeds(); foreach (var breeds in breedsList) { var breedsInDB = await breedsRepository.GetBreeds(breeds.Id); if (breedsInDB == null) { breedsInDB = new Breeds(breeds.Id, breeds.Name); breedsInDB.SetOrigin(breeds.Origin); breedsInDB.SetTemperament(breeds.Temperament); breedsInDB.SetDescription(breeds.Description); await breedsRepository.AddBreeds(breedsInDB); } var imagesList = await theCatAPI.GetImagesByBreeds(breeds.Id); if (imagesList != null && imagesList.Count > 0) { foreach (var image in imagesList) { var imageInDB = await imageUrlRepository.GetImageUrl(image.Id); var imageExists = imageInDB != null; if (!imageExists) { imageInDB = new ImageUrl(image.Id, image.Url); imageInDB.SetWidth(image.Width); imageInDB.SetHeight(image.Height); } imageInDB.SetBreeds(breedsInDB); if (!imageExists) { await imageUrlRepository.AddImageUrl(imageInDB); } else { await imageUrlRepository.UpdateImageUrl(imageInDB); } } } } }