/// <summary> /// Delete equipment record /// </summary> /// <param name="id">id of Equipment to delete</param> /// <response code="200">OK</response> /// <response code="404">Equipment not found</response> public virtual IActionResult EquipmentIdDeletePostAsync(int id) { bool exists = _context.Equipments.Any(a => a.Id == id); if (exists) { // remove associated seniority audits RemoveSeniorityAudits(id); Equipment item = _context.Equipments .Include(x => x.LocalArea) .Include(x => x.DistrictEquipmentType) .Include(x => x.DistrictEquipmentType.EquipmentType) .First(a => a.Id == id); int localAreaId = -1; int districtEquipmentTypeId = -1; int equipmentTypeId = -1; if (item.LocalArea != null && item.DistrictEquipmentType != null && item.DistrictEquipmentType.EquipmentType != null) { localAreaId = item.LocalArea.Id; districtEquipmentTypeId = item.DistrictEquipmentType.Id; equipmentTypeId = item.DistrictEquipmentType.EquipmentType.Id; } _context.Equipments.Remove(item); // save the changes _context.SaveChanges(); // update the seniority list if (localAreaId != -1 && districtEquipmentTypeId != -1 && equipmentTypeId != -1) { _context.CalculateSeniorityList(localAreaId, districtEquipmentTypeId, equipmentTypeId, _configuration); } return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// /// </summary> /// <param name="id">id of Equipment to delete</param> /// <response code="200">OK</response> /// <response code="404">Equipment not found</response> public virtual IActionResult EquipmentIdDeletePostAsync(int id) { var exists = _context.Equipments.Any(a => a.Id == id); if (exists) { // remove associated seniority audits. RemoveSeniorityAudits(id); var item = _context.Equipments .Include(x => x.LocalArea) .Include(x => x.DistrictEquipmentType.EquipmentType) .First(a => a.Id == id); int localAreaId = -1; int equipmentTypeId = -1; if (item.LocalArea != null && item.DistrictEquipmentType != null && item.DistrictEquipmentType.EquipmentType != null) { localAreaId = item.LocalArea.Id; equipmentTypeId = item.DistrictEquipmentType.EquipmentType.Id; } _context.Equipments.Remove(item); // Save the changes _context.SaveChanges(); // update the seniority list if (localAreaId != -1 && equipmentTypeId != -1) { _context.CalculateSeniorityList(localAreaId, equipmentTypeId); } return(new ObjectResult(item)); } else { // record not found return(new StatusCodeResult(404)); } }