public async Task <bool> UpdateBuilding([FromUri] int id, [FromBody] BuildingCreateAndUpdate model) { var entity = _context. Buildings. Single(e => e.BuildingId == id); entity.BuildingName = model.BuildingName; return(await _context.SaveChangesAsync() == 1); }
//==========================CREATE===============================// public async Task <bool> CreateNewBuilding(BuildingCreateAndUpdate model) { var entity = new Building() { BuildingName = model.BuildingName, Active = true }; _context.Buildings.Add(entity); return(await _context.SaveChangesAsync() == 1); }
public async Task <IHttpActionResult> Create(BuildingCreateAndUpdate model) { { //check if model is valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //instantiate the service BuildingService service = CreateBuildingService(); if (await service.CreateNewBuilding(model) == false) { return(InternalServerError()); //500 } return(Ok("Building Added")); //200 with custom message } }
public async Task <IHttpActionResult> Update([FromUri] int id, [FromBody] BuildingCreateAndUpdate model) { { //check if model is valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //instantiate the service BuildingService service = CreateBuildingService(); if (await service.UpdateBuilding(id, model) == false) { return(InternalServerError()); } return(Ok("Building Updated")); //200 with custom message } }