Beispiel #1
0
        public void Remove(int id)
        {
            var equipment = entities.Equipments.FirstOrDefault(x => x.ID == id);

            entities.Equipments.Remove(equipment);
            entities.SaveChanges();
        }
 public IHttpActionResult PutEquipment([FromBody] EquipmentViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid model"));
     }
     using (var context = new EquipmentEntities())
     {
         var existingEquipment = context.EQUIPMENTs.Where(s => s.ID == model.ID).
                                 FirstOrDefault <EQUIPMENT>();
         if (existingEquipment != null)
         {
             existingEquipment.Type        = model.Type;
             existingEquipment.Name        = model.Name;
             existingEquipment.Status      = model.Status;
             existingEquipment.Description = model.Description;
             context.SaveChanges();
         }
         else
         {
             return(NotFound());
         }
     }
     return(Ok());
 }
 public IHttpActionResult DeleteEquipment(string id)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("invalid request"));
     }
     using (var context = new EquipmentEntities())
     {
         var equip = context.EQUIPMENTs.Where(s => s.ID == id).FirstOrDefault();
         if (equip == null)
         {
             return(NotFound());
         }
         context.Entry(equip).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
         return(Ok());
     }
 }
 public IHttpActionResult PostNewEquipment([FromBody] EquipmentViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid model"));
     }
     using (var context = new EquipmentEntities())
     {
         var result = context.INSERT_EQUIPMENT(model.Type, model.Name, model.Status, model.Description);
         if (result == 1)
         {
             context.SaveChanges();
             return(Ok());
         }
         else
         {
             return(BadRequest("Server error"));
         }
     }
 }