public virtual IActionResult ConditionTypesIdGet([FromRoute] int id) { // get condition type HetConditionType conditionType = _context.HetConditionType.AsNoTracking() .Include(x => x.District) .FirstOrDefault(x => x.ConditionTypeId == id); return(new ObjectResult(new HetsResponse(conditionType))); }
public virtual IActionResult ConditionTypesIdPost([FromRoute] int id, [FromBody] HetConditionType item) { if (id != item.ConditionTypeId) { // record not found return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } // add or update contact if (item.ConditionTypeId > 0) { bool exists = _context.HetConditionType.Any(a => a.ConditionTypeId == id); if (!exists) { // record not found return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } // get record HetConditionType condition = _context.HetConditionType.First(x => x.ConditionTypeId == id); condition.ConcurrencyControlNumber = item.ConcurrencyControlNumber; condition.ConditionTypeCode = item.ConditionTypeCode; condition.Description = item.Description; condition.Active = item.Active; condition.DistrictId = item.District.DistrictId; } else { HetConditionType condition = new HetConditionType { ConcurrencyControlNumber = item.ConcurrencyControlNumber, ConditionTypeCode = item.ConditionTypeCode, Description = item.Description, Active = item.Active, DistrictId = item.District.DistrictId }; _context.HetConditionType.Add(condition); } _context.SaveChanges(); // get the id (in the case of new records) id = item.ConditionTypeId; // return the updated condition type record HetConditionType conditionType = _context.HetConditionType.AsNoTracking() .Include(x => x.District) .FirstOrDefault(x => x.ConditionTypeId == id); return(new ObjectResult(new HetsResponse(conditionType))); }
public virtual IActionResult ConditionTypesIdDeletePost([FromRoute] int id) { bool exists = _context.HetConditionType.Any(a => a.ConditionTypeId == id); // not found if (!exists) { return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } HetConditionType item = _context.HetConditionType.First(a => a.ConditionTypeId == id); _context.HetConditionType.Remove(item); // save changes _context.SaveChanges(); return(new ObjectResult(new HetsResponse(item))); }