Exemplo n.º 1
0
        // DELETE: api/Spell/5
        public IHttpActionResult Delete(int id)
        {
            using (SpellContext db = new SpellContext())
            {
                try
                {
                    Spell spell = db.Spells.Where(x => x.id == id).FirstOrDefault();
                    db.Spells.Remove(spell);
                    db.SaveChanges();
                    return Ok("Spell " + spell.id + " (" + spell.name + ") Removed Successfully!");
                }
                catch
                {
                    return InternalServerError();
                }

            }
        }
Exemplo n.º 2
0
        // POST: api/Spell
        public IHttpActionResult Post([FromBody]Spell spell)
        {
            using (SpellContext db = new SpellContext())
            {

                var recordToUpdate = db.Spells.Where(x => x.id == spell.id).FirstOrDefault();

                if (recordToUpdate != null)
                {
                    recordToUpdate.name = spell.name;
                    recordToUpdate.desc = spell.desc;
                    recordToUpdate.higher_level = spell.higher_level;
                    recordToUpdate.page = spell.page;
                    recordToUpdate.range = spell.range;
                    recordToUpdate.components = spell.components;
                    recordToUpdate.material = spell.material;
                    recordToUpdate.ritual = spell.ritual;
                    recordToUpdate.duration = spell.duration;
                    recordToUpdate.concentration = spell.concentration;
                    recordToUpdate.casting_time = spell.casting_time;
                    recordToUpdate.level = spell.level;
                    recordToUpdate.school = spell.school;
                    recordToUpdate.class_name = spell.class_name;
                    db.SaveChanges();
                    return Ok("Spell " + spell.id + " (" + spell.name + ") Updated Successfully!");
                }
                else
                {
                    return InternalServerError();
                }

            }
        }
Exemplo n.º 3
0
 // PUT: api/Spell/5
 public IHttpActionResult Put([FromBody]Spell spell)
 {
     using (SpellContext db = new SpellContext())
     {
         try
         {
             spell.id = db.Spells.Count() + 1;
             db.Spells.Add(spell);
             db.SaveChanges();
             return Ok("Spell " + spell.id + " (" + spell.name + ") Added Successfully!");
         }
         catch
         {
             return InternalServerError();
         }
     }
 }