public int Add(string name, DateTime birthDate, string speciesName, string categoryName, string description, bool isVaccinated, decimal price, string color, string userId, string image, Pet pet = null)
        {
            var currentPetSpecies = new Species();
            var species = this.species.All().Where(s => s.Name == speciesName).ToList();

            if (species.Count == 0)
            {
                var currentPetCategory = new Category();
                var categories = this.categories.All().Where(c => c.Name == categoryName).ToList();

                if (categories.Count == 0)
                {
                    currentPetCategory.Name = categoryName;
                }
                else
                {
                    currentPetCategory = categories[0];
                }

                currentPetSpecies.Category = currentPetCategory;
                currentPetSpecies.Name = speciesName;
            }
            else
            {
                currentPetSpecies = species[0];
            }

            var currentPetColor = new Color();
            var colors = this.colors.All().Where(c => c.Name == color).ToList();

            if (colors.Count == 0)
            {
                currentPetColor.Name = color;
            }
            else
            {
                currentPetColor = colors[0];
            }

            var currentPet = new Pet();

            if (pet != null)
            {
                currentPet = pet;
            }

            currentPet.Name = name;
            currentPet.BirthDate = birthDate;
            currentPet.Species = currentPetSpecies;
            currentPet.Description = description;
            currentPet.IsVaccinated = isVaccinated;
            currentPet.Price = price;
            currentPet.Color = currentPetColor;
            currentPet.UserId = userId;
            currentPet.Name = name;

            if (image != null)
            {
                currentPet.Image = new PetImage() { Image = image };
            }

            if (pet != null)
            {
                this.pets.Update(currentPet);
            }
            else
            {
                this.pets.Add(currentPet);
            }

            this.pets.SaveChanges();

            return currentPet.Id;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set parameter values that each species need to know
        /// - from pasture to species
        /// </summary>
        /// <param name="s">The s.</param>
        private void InitSpeciesValues(int s)
        {
            SP[s] = new Species(speciesName[s]);

            SP[s].isLegume = (speciesNType[s].ToLower() == "legume" ? true : false);
            SP[s].photoPath = speciesCType[s].ToUpper();
            SP[s].dmshoot = iniDMshoot[s];
            if (iniDMroot[s] >= 0.0)
                SP[s].dmroot = iniDMroot[s];
            else
                SP[s].dmroot = iniDMshoot[s] * maxRootFraction[s] / (1 + maxRootFraction[s]);
            SP[s].rootDepth = iniRootDepth[s];

            SP[s].Pm = maxPhotosynthesisRate[s];
            SP[s].maintRespiration = maintenanceRespirationCoef[s];
            SP[s].growthEfficiency = growthEfficiency[s];
            SP[s].lightExtCoeff = lightExtentionCoeff[s];
            SP[s].growthTmin = growthTmin[s];
            SP[s].growthTmax = growthTmax[s];
            SP[s].growthTopt = growthTopt[s];
            SP[s].growthTq = growthTq[s];
            SP[s].massFluxTmin = massFluxTmin[s];
            SP[s].massFluxTopt = massFluxTopt[s];
            SP[s].massFluxW0 = massFluxW0[s];
            SP[s].massFluxWopt = MassFluxWopt[s];
            SP[s].heatOnsetT = heatOnsetT[s];
            SP[s].heatFullT = heatFullT[s];
            SP[s].heatSumT = heatSumT[s];
            SP[s].coldOnsetT = coldOnsetT[s];
            SP[s].coldFullT = coldFullT[s];
            SP[s].coldSumT = coldSumT[s];
            SP[s].SLA = specificLeafArea[s];
            SP[s].SRL = specificRootLength[s];
            SP[s].maxSRratio = (1 - maxRootFraction[s]) / maxRootFraction[s];
            SP[s].allocationSeasonF = allocationSeasonF[s];
            SP[s].fLeaf = fracToLeaf[s];
            SP[s].fStolon = fracToStolon[s];
            SP[s].rateLive2Dead = TurnoverRateLive2Dead[s];
            SP[s].rateDead2Litter = TurnoverRateDead2Litter[s];
            SP[s].rateRootSen = TurnoverRateRootSenescence[s];
            SP[s].stockParameter = StockParameter[s];
            SP[s].digestLive = DigestibilityLive[s];
            SP[s].digestDead = DigestibilityDead[s];
            SP[s].dmgreenmin = MinimumGreenWt[s];
            SP[s].dmdeadmin = MinimumDeadWt[s];
            SP[s].NcleafOpt = LeafNopt[s] * 0.01;   // convert % to fraction
            SP[s].NcleafMax = LeafNmax[s] * 0.01;
            SP[s].NcleafMin = LeafNmin[s] * 0.01;
            SP[s].NcstemFr = RelativeNStems[s];
            SP[s].NcstolFr = RelativeNStolons[s];
            SP[s].NcrootFr = RelativeNRoots[s];
            SP[s].NcRel2 = RelativeNStage2[s];
            SP[s].NcRel3 = RelativeNStage3[s];
            SP[s].MinFix = MinimumNFixation[s];
            SP[s].MaxFix = MaximumNFixation[s];
            SP[s].NdilutCoeff = DillutionCoefN[s];
            SP[s].Kappa2 = Kappa2Remob[s];
            SP[s].Kappa3 = Kappa3Remob[s];
            SP[s].Kappa4 = Kappa4Remob[s];
            SP[s].gfGen = GlfGeneric[s];
            SP[s].referenceCO2 = ReferenceCO2[s];
            SP[s].CO2PmaxScale = offsetCO2EffectOnPhotosynthesis[s];
            SP[s].CO2NScale = OffsetCO2EffectOnNuptake[s];
            SP[s].CO2NMin = MinimumCO2EffectOnNuptake[s];
            SP[s].CO2NCurvature = ExponentCO2EffectOnNuptake[s];
            SP[s].waterStressFactor = WaterStressFactor[s];
            SP[s].soilSatFactor = WaterLoggingFactor[s];

            SP[s].InitValues();
        }