Exemple #1
0
        public IHttpActionResult Put(SpeciesListItem model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSpeciesService();

            if (!service.UpdateSpecies(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemple #2
0
        public SpeciesListItem GetSpeciesById(int speciesId)
        {
            SpeciesListItem result = new SpeciesListItem();

            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .Species
                    .Single(b => b.Id == speciesId);
                result.Id          = query.Id;
                result.SpeciesName = query.SpeciesName;
                result.Weakness    = query.Weakness;
                result.Strength    = query.Strength;
                result.HistoryId   = query.HistoryId;


                return(result);
            }
        }
Exemple #3
0
        public bool UpdateSpecies(SpeciesListItem model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .Species
                    .SingleOrDefault(e => e.Id == model.Id);

                if (query != null)
                {
                    query.SpeciesName = model.SpeciesName;
                    query.Strength    = model.Strength;
                    query.Weakness    = model.Weakness;
                    query.HistoryId   = model.HistoryId;
                    return(ctx.SaveChanges() == 1);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #4
0
        public List <SpeciesListItem> GetSpeciesByGameId(int gameId)
        {
            List <SpeciesListItem> result = new List <SpeciesListItem>();

            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx.Games
                    .Single(e => e.Id == gameId);

                foreach (Species s in query.ListOfSpecies)
                {
                    SpeciesListItem e = new SpeciesListItem();
                    e.Id          = s.Id;
                    e.SpeciesName = s.SpeciesName;
                    e.Strength    = s.Strength;
                    e.Weakness    = s.Weakness;
                    e.HistoryId   = s.HistoryId;

                    result.Add(e);
                }
                return(result);
            }
        }