public async Task <IActionResult> UpdateItem(long id, cojAgencyBuildingCondo item) { try { if (id != item.id) { return(NoContent()); } //Add new cojAgencyBuildingCondo _itemNew = new cojAgencyBuildingCondo { idRef = item.idRef, cojAgencyBuildingId = item.cojAgencyBuildingId, cojCondoUnit = item.cojCondoUnit, cojCondoBuilding = item.cojCondoBuilding }; _context.cojAgencyBuildingCondos.Add(_itemNew); await _context.SaveChangesAsync(); return(Ok(_itemNew)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult <cojAgencyBuildingCondo> > CreateItem(cojAgencyBuildingCondo newItem) { try { //check duplicate item id, code, name if (newItem.id != 0) { return(NoContent()); } newItem.startDate = DateTime.Now.ToString(_culture); newItem.endDate = "31/12/9999 00:00:00"; _context.cojAgencyBuildingCondos.Add(newItem); await _context.SaveChangesAsync(); newItem.idRef = newItem.id; return(CreatedAtAction(nameof(GetItem), new { id = newItem.id }, newItem)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }