public IHttpActionResult PutPlacementList(int id, PlacementList placementList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != placementList.Id) { return(BadRequest()); } db.Entry(placementList).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PlacementListExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetPlacementList(int id) { PlacementList placementList = db.PlacementList.Find(id); if (placementList == null) { return(NotFound()); } return(Ok(placementList)); }
public IHttpActionResult PostPlacementList(PlacementList placementList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PlacementList.Add(placementList); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = placementList.Id }, placementList)); }
public static void Register(Type type) { try { if (!type.IsSubclassOf(typeof(Entity))) { return; } EntityDefinitionAttribute attr = type.GetCustomAttribute <EntityDefinitionAttribute>(); if (attr == null) { Logger.Log(LogLevel.Error, $"Entity {type} does not have a definition attribute"); return; } string id = attr.ID; ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(EntityData), typeof(Room) }); if (ctor == null) { Logger.Log(LogLevel.Error, $"Entity of type {type} with ID {id} does not have a valid ctor"); return; } FieldInfo placementsField = null; if ((placementsField = type.GetField("Placements", BindingFlags.Public | BindingFlags.Static)) != null) { if (placementsField.FieldType == typeof(PlacementList)) { PlacementList placements = (PlacementList)placementsField.GetValue(null); foreach (Placement p in placements) { p.Parent = type; EntityPlacements.Add(p); } Logger.Log($"Registered {placements.Count} placements for {attr.ID}"); } } EntityCreators.Add(id, (EntityData d, Room r) => (Entity)ctor.Invoke(new object[] { d, r })); Logger.Log($"Registered entity {id} of type {type}"); } catch (Exception e) { Logger.Log(LogLevel.Error, $"Encountered an error while attempting to register entity {type}"); Logger.LogException(e); } }
public void SearchPlacements(string searchString) { PlacementList.Clear(); var placements = _placementService.SearchPlacements(searchString); foreach (var placement in placements) { var openingViewModel = new PlacementViewModel(placement); PlacementList.Add(openingViewModel); } }
public IHttpActionResult DeletePlacementList(int id) { PlacementList placementList = db.PlacementList.Find(id); if (placementList == null) { return(NotFound()); } db.PlacementList.Remove(placementList); db.SaveChanges(); return(Ok(placementList)); }