public async Task <ActionResult <SpecieModel> > CreateSpecie(SpecieModel specie)
        {
            try {
                dBContext.Species.Add(specie);
                await dBContext.SaveChangesAsync();

                return(Ok(specie));
            }
            catch (Exception e) {
                return(StatusCode(410));
            }
        }
示例#2
0
 public void BuildProfile(JObject result)
 {
     Profile = new SpecieModel
     {
         Name            = result.SelectToken("name").ToString(),
         Classification  = result.SelectToken("classification").ToString(),
         Designation     = result.SelectToken("designation").ToString(),
         AverageHeight   = result.SelectToken("average_height").ToString(),
         SkinColors      = result.SelectToken("skin_colors").ToString(),
         HairColors      = result.SelectToken("hair_colors").ToString(),
         EyeColors       = result.SelectToken("eye_colors").ToString(),
         AverageLifeSpan = result.SelectToken("average_lifespan").ToString(),
         HomeWorld       = MakeRequest.GetSpecificData(result.SelectToken("homeworld").ToString()).SelectToken("name").ToString(),
         Language        = result.SelectToken("language").ToString(),
         People          = GetNames.Get("people", result),
         Films           = GetNames.Get("films", result),
         Url             = result.SelectToken("url").ToObject <Uri>()
     };
 }
        public async Task <IActionResult> UpdateSpecie(SpecieModel specie, long id)
        {
            try {
                if (id != specie.IdSpecie)
                {
                    return(BadRequest());
                }
                dBContext.Entry(specie).State = EntityState.Modified;
                await dBContext.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception e) {
                bool specieExist = dBContext.Species.Any(e => e.IdSpecie == id);
                if (!specieExist)
                {
                    return(NotFound());
                }
                return(StatusCode(410));
            }
        }