public IHttpActionResult DeleteRecords(IEnumerable <EditableGridModel> records) { try { var service = new XrmServiceContext(_conn); service.DeleteRecords(records); return(Ok()); } catch (Exception ex) { if (ex.Message.Equals("The object you tried to delete is associated with another object and cannot be deleted.")) { throw new InvalidOperationException("Record/s cannot be deleted. It is already used in transactions."); } else { return(InternalServerError(ex)); } } }